67 Commits

Author SHA1 Message Date
argoyle 46e1bd284c fix: prohibit concurrent read/write 2023-12-26 18:21:59 +01:00
argoyle 16e5ad4f23 build(deps): bump github.com/sparetimecoders/goamqp from 0.2.0 to 0.2.1
Bumps [github.com/sparetimecoders/goamqp](https://github.com/sparetimecoders/goamqp) from 0.2.0 to 0.2.1.
- [Release notes](https://github.com/sparetimecoders/goamqp/releases)
- [Commits](https://github.com/sparetimecoders/goamqp/compare/v0.2.0...v0.2.1)
2023-12-19 05:19:45 +00:00
argoyle f5c18e4515 ci: update version of Go 2023-12-11 17:31:32 +01:00
argoyle e3c79092c2 ci: update to go 1.21.3 and remove patch level 2023-10-27 14:12:51 +02:00
argoyle 7815c85c92 build(deps): bump github.com/sparetimecoders/goamqp from 0.1.5 to 0.2.0
Bumps [github.com/sparetimecoders/goamqp](https://github.com/sparetimecoders/goamqp) from 0.1.5 to 0.2.0.
- [Release notes](https://github.com/sparetimecoders/goamqp/releases)
- [Commits](https://github.com/sparetimecoders/goamqp/compare/v0.1.5...v0.2.0)
2023-10-05 05:19:27 +00:00
argoyle de664d7a05 chore: use 1.21.1 in go.mod for Dependabot 2023-09-27 21:09:56 +02:00
argoyle 67963fcdc1 ci: update to Go 1.21.1 for vulnerabilities 2023-09-08 07:06:55 +02:00
argoyle d3a504ca68 ci: update to Golang 1.21.0 2023-08-30 20:19:14 +02:00
argoyle 233197999f ci: update pre-commit versions 2023-08-30 18:01:12 +02:00
argoyle 1ea2469c77 ci: update to Go 1.20.7 2023-08-07 08:37:15 +02:00
argoyle 775553c2d5 build(deps): bump github.com/sparetimecoders/goamqp from 0.1.4 to 0.1.5
Bumps [github.com/sparetimecoders/goamqp](https://github.com/sparetimecoders/goamqp) from 0.1.4 to 0.1.5.
- [Release notes](https://github.com/sparetimecoders/goamqp/releases)
- [Commits](https://github.com/sparetimecoders/goamqp/compare/v0.1.4...v0.1.5)
2023-07-04 05:19:53 +00:00
argoyle 4203f4474f ci: make releases handle multi-line release notes 2023-06-08 16:16:15 +02:00
argoyle cc7de2e5a1 ci: update Go version 2023-06-08 16:12:38 +02:00
argoyle f14aec80d9 ci: update golangci-lint 2023-06-04 16:45:07 +02:00
argoyle cbd358ba85 build(deps): bump github.com/stretchr/testify from 1.8.3 to 1.8.4
Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.8.3 to 1.8.4.
- [Release notes](https://github.com/stretchr/testify/releases)
- [Commits](https://github.com/stretchr/testify/compare/v1.8.3...v1.8.4)
2023-05-31 05:19:33 +00:00
argoyle df845a7b4b chore: update pre-commit and fix golangci-lint 2023-05-19 10:48:32 +02:00
argoyle d8f6785032 build(deps): bump github.com/stretchr/testify from 1.8.2 to 1.8.3
Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.8.2 to 1.8.3.
- [Release notes](https://github.com/stretchr/testify/releases)
- [Commits](https://github.com/stretchr/testify/compare/v1.8.2...v1.8.3)
2023-05-19 05:19:34 +00:00
argoyle ff779d9456 build(deps): bump github.com/sparetimecoders/goamqp from 0.1.3 to 0.1.4
Bumps [github.com/sparetimecoders/goamqp](https://github.com/sparetimecoders/goamqp) from 0.1.3 to 0.1.4.
- [Release notes](https://github.com/sparetimecoders/goamqp/releases)
- [Commits](https://github.com/sparetimecoders/goamqp/compare/v0.1.3...v0.1.4)
2023-05-11 05:19:41 +00:00
argoyle eba7784e59 ci: update Go version and fix gitlabci lint 2023-05-04 08:34:40 +02:00
argoyle d022eb8ebd ci: update to Go 1.20.3 2023-04-06 10:26:35 +02:00
argoyle 9c802b1239 ci: update Go verion for vulnerabilities scan 2023-03-09 22:00:21 +01:00
argoyle 2e3bd451df build(deps): bump github.com/stretchr/testify from 1.8.1 to 1.8.2
Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.8.1 to 1.8.2.
- [Release notes](https://github.com/stretchr/testify/releases)
- [Commits](https://github.com/stretchr/testify/compare/v1.8.1...v1.8.2)
2023-02-26 10:22:34 +00:00
argoyle 0608960a02 ci: update to golang 1.20.1 2023-02-26 11:03:49 +01:00
argoyle bbbfb99dd9 ci: change dependabot rebase strategy 2023-01-29 10:52:30 +01:00
argoyle eef42d4b32 ci: update to Go 1.19.5 2023-01-29 10:52:23 +01:00
argoyle d1a9414390 ci: add release handling 2023-01-29 10:52:12 +01:00
argoyle dee3bb5d60 ci: add local module to pre-commit config 2023-01-13 13:39:34 +01:00
argoyle dcbdef35cf ci: add pre-commit and remove those checks from test step 2022-12-28 20:06:28 +01:00
argoyle 1794fcd2ad build(deps): bump github.com/sparetimecoders/goamqp from 0.1.2 to 0.1.3
Bumps [github.com/sparetimecoders/goamqp](https://github.com/sparetimecoders/goamqp) from 0.1.2 to 0.1.3.
- [Release notes](https://github.com/sparetimecoders/goamqp/releases)
- [Commits](https://github.com/sparetimecoders/goamqp/compare/v0.1.2...v0.1.3)
2022-11-15 05:19:17 +00:00
argoyle abfeb751b2 chore: replace deprecated ioutil.ReadAll 2022-11-10 10:54:45 +01:00
argoyle 51f0aaf0ca build(deps): bump github.com/sparetimecoders/goamqp from 0.1.1 to 0.1.2
Bumps [github.com/sparetimecoders/goamqp](https://github.com/sparetimecoders/goamqp) from 0.1.1 to 0.1.2.
- [Release notes](https://github.com/sparetimecoders/goamqp/releases)
- [Commits](https://github.com/sparetimecoders/goamqp/compare/v0.1.1...v0.1.2)
2022-10-26 05:19:33 +00:00
argoyle 8604a3568a build(deps): bump github.com/stretchr/testify from 1.8.0 to 1.8.1
Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.8.0 to 1.8.1.
- [Release notes](https://github.com/stretchr/testify/releases)
- [Commits](https://github.com/stretchr/testify/compare/v1.8.0...v1.8.1)
2022-10-24 05:19:21 +00:00
argoyle fee49889cf fix: run builds with Go 1.19.2 to fix vulnerabilities 2022-10-11 17:59:59 +02:00
argoyle 7e70411553 ci: add vulnerability-check 2022-09-13 14:18:20 +02:00
argoyle 610edd6576 chore: switch to moved goamqp 2022-07-20 17:25:13 +02:00
argoyle 2f232e6850 build(deps): bump github.com/stretchr/testify from 1.7.5 to 1.8.0
Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.7.5 to 1.8.0.
- [Release notes](https://github.com/stretchr/testify/releases)
- [Commits](https://github.com/stretchr/testify/compare/v1.7.5...v1.8.0)
2022-06-30 05:19:15 +00:00
argoyle be4409a745 build(deps): bump github.com/stretchr/testify from 1.7.4 to 1.7.5
Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.7.4 to 1.7.5.
- [Release notes](https://github.com/stretchr/testify/releases)
- [Commits](https://github.com/stretchr/testify/compare/v1.7.4...v1.7.5)
2022-06-24 05:19:11 +00:00
argoyle 83b513ebf8 build(deps): bump github.com/stretchr/testify from 1.7.2 to 1.7.4
Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.7.2 to 1.7.4.
- [Release notes](https://github.com/stretchr/testify/releases)
- [Commits](https://github.com/stretchr/testify/compare/v1.7.2...v1.7.4)
2022-06-21 05:19:14 +00:00
argoyle 51e8d43795 build(deps): bump github.com/stretchr/testify from 1.7.1 to 1.7.2
Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.7.1 to 1.7.2.
- [Release notes](https://github.com/stretchr/testify/releases)
- [Commits](https://github.com/stretchr/testify/compare/v1.7.1...v1.7.2)
2022-06-07 05:19:13 +00:00
argoyle e816866e75 build(deps): bump gitlab.com/sparetimecoders/goamqp from 0.4.0 to 0.5.0
Bumps [gitlab.com/sparetimecoders/goamqp](https://gitlab.com/sparetimecoders/goamqp) from 0.4.0 to 0.5.0.
- [Release notes](https://gitlab.com/sparetimecoders/goamqp/tags)
- [Commits](https://gitlab.com/sparetimecoders/goamqp/compare/v0.4.0...v0.5.0)
2022-05-26 05:19:12 +00:00
argoyle ad1bf3cbfa Merge branch 'dependabot-go_modules-github.com-stretchr-testify-1.7.1' into 'main'
build(deps): bump github.com/stretchr/testify from 1.7.0 to 1.7.1

See merge request unboundsoftware/shiny/authz_client!11
2022-03-16 07:29:17 +00:00
argoyle f4e3891f62 build(deps): bump github.com/stretchr/testify from 1.7.0 to 1.7.1
Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.7.0 to 1.7.1.
- [Release notes](https://github.com/stretchr/testify/releases)
- [Commits](https://github.com/stretchr/testify/compare/v1.7.0...v1.7.1)
2022-03-16 05:19:33 +00:00
argoyle cf73d6c399 build: add params to codecov 2022-02-20 00:56:58 +01:00
argoyle 74e81114de Merge branch 'dependabot-go_modules-gitlab.com-sparetimecoders-goamqp-0.4.0' into 'main'
chore(deps): bump gitlab.com/sparetimecoders/goamqp from 0.3.2 to 0.4.0

See merge request unboundsoftware/shiny/authz_client!10
2022-02-12 10:27:36 +00:00
argoyle 2299434912 chore(deps): bump gitlab.com/sparetimecoders/goamqp from 0.3.2 to 0.4.0
Bumps [gitlab.com/sparetimecoders/goamqp](https://gitlab.com/sparetimecoders/goamqp) from 0.3.2 to 0.4.0.
- [Release notes](https://gitlab.com/sparetimecoders/goamqp/tags)
- [Commits](https://gitlab.com/sparetimecoders/goamqp/compare/v0.3.2...v0.4.0)
2022-02-12 05:19:39 +00:00
argoyle 3c6ab4bfde Merge branch 'codecov' into 'main'
ci: change to codecov binary instead of bash uploader

See merge request unboundsoftware/shiny/authz_client!9
2021-11-17 05:16:41 +00:00
argoyle a305db2206 ci: change to codecov binary instead of bash uploader 2021-11-17 06:14:49 +01:00
argoyle 6e8b78c6e2 Merge branch 'dependabot' into 'main'
ci: remove dependabot-standalone

See merge request unboundsoftware/shiny/authz_client!8
2021-11-03 17:45:18 +00:00
argoyle 4578694015 ci: remove dependabot-standalone 2021-11-03 18:25:05 +01:00
argoyle dbc4412b9b Merge branch 'fix-pipeline' into 'main'
fix: pipeline

See merge request unboundsoftware/shiny/authz_client!7
2021-10-28 12:56:44 +00:00
argoyle f151464330 fix: pipeline 2021-10-28 14:54:47 +02:00
argoyle bcfa15e4a2 Merge branch 'dependabot-go_modules-github.com-stretchr-testify-1.7.0' into 'main'
chore(deps): bump github.com/stretchr/testify from 1.4.0 to 1.7.0

See merge request unboundsoftware/shiny/authz_client!5
2021-10-26 10:35:08 +00:00
argoyle 41c7e4a3ef chore(deps): bump github.com/stretchr/testify from 1.4.0 to 1.7.0
Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.4.0 to 1.7.0.
- [Release notes](https://github.com/stretchr/testify/releases)
- [Commits](https://github.com/stretchr/testify/compare/v1.4.0...v1.7.0)
2021-10-26 12:33:10 +02:00
argoyle 5cdd3bd244 Merge branch 'dependabot-go_modules-gitlab.com-sparetimecoders-goamqp-0.3.2' into 'main'
chore(deps): bump gitlab.com/sparetimecoders/goamqp from 0.3.1 to 0.3.2

See merge request unboundsoftware/shiny/authz_client!6
2021-10-26 09:07:55 +00:00
argoyle 398d267ee5 chore(deps): bump gitlab.com/sparetimecoders/goamqp from 0.3.1 to 0.3.2
Bumps [gitlab.com/sparetimecoders/goamqp](https://gitlab.com/sparetimecoders/goamqp) from 0.3.1 to 0.3.2.
- [Release notes](https://gitlab.com/sparetimecoders/goamqp/tags)
- [Commits](https://gitlab.com/sparetimecoders/goamqp/compare/v0.3.1...v0.3.2)
2021-10-26 05:43:34 +00:00
argoyle 26f8e762c7 Merge branch 'dependabot' into 'main'
chore: add dependabot config

See merge request unboundsoftware/shiny/authz_client!4
2021-10-26 05:22:59 +00:00
argoyle e395518de2 chore: add dependabot config 2021-10-26 07:21:08 +02:00
argoyle 60795d413d Merge branch 'update-goamqp' into 'main'
chore: update to latest version of goamqp

See merge request unboundsoftware/shiny/authz_client!3
2021-05-15 12:44:05 +00:00
argoyle a2164c4beb chore: update to latest version of goamqp 2021-05-15 14:42:19 +02:00
argoyle 90e028b173 Merge branch 'group-imports' into 'main'
chore: group imports

See merge request unboundsoftware/shiny/authz_client!2
2021-05-03 18:54:24 +00:00
argoyle 6ce176b927 chore: group imports 2021-05-03 20:52:15 +02:00
argoyle 48a063eba2 chore: rename master -> main 2021-04-07 09:49:09 +02:00
argoyle 5634c26039 Merge branch 'ci-workflows' into 'master'
chore: add CI workflows

See merge request unboundsoftware/shiny/authz_client!1
2020-11-23 16:43:28 +00:00
argoyle 429f45935a chore: add CI workflows 2020-11-23 17:20:09 +01:00
argoyle 3c36225665 chore: change coverage badge to codecov.io 2020-07-03 21:31:34 +02:00
argoyle f6417140cb chore: simplify pipeline 2020-06-26 20:44:52 +02:00
argoyle fb0273fe3c chore: add codecov upload 2020-04-27 19:27:48 +02:00
9 changed files with 242 additions and 85 deletions
+61 -27
View File
@@ -1,41 +1,75 @@
variables:
GOCACHE: "${CI_PROJECT_DIR}/_go/cache"
include:
- template: 'Workflows/MergeRequest-Pipelines.gitlab-ci.yml'
before_script:
- mkdir -p ${CI_PROJECT_DIR}/_go/{pkg,bin,cache}
- rm -rf /go/pkg || true
- mkdir -p /go
- ln -s ${CI_PROJECT_DIR}/_go/pkg /go/pkg
- ln -s ${CI_PROJECT_DIR}/_go/bin /go/bin
cache:
key: "$CI_COMMIT_REF_NAME"
paths:
- _go
untracked: true
image: golang:1.21.5
stages:
- deps
- test
- deps
- test
- prepare
- release
run-pre-commit:
stage: .pre
image: unbound/pre-commit
variables:
PRE_COMMIT_HOME: ${CI_PROJECT_DIR}/.cache/pre-commit
cache:
- key:
files:
- .pre-commit-config.yaml
paths:
- ${PRE_COMMIT_HOME}
script:
- pre-commit run --all-files
deps:
stage: deps
image: golang:1.14
script:
- go mod download
- go mod download
test:
stage: test
dependencies:
- deps
image: golang:1.14
- deps
script:
- go fmt $(go list ./...)
- go vet $(go list ./...)
- unset "${!CI@}"
- CGO_ENABLED=1 go test -p 1 -mod=readonly -race -coverprofile=.testCoverage.txt -covermode=atomic -coverpkg=$(go list ./... | tr '\n' , | sed 's/,$//') ./...
- go tool cover -html=.testCoverage.txt -o coverage.html
- go tool cover -func=.testCoverage.txt
- CGO_ENABLED=1 go test -mod=readonly -race -coverprofile=coverage.txt -covermode=atomic -coverpkg=$(go list ./... | tr '\n' , | sed 's/,$//') ./...
- go tool cover -html=coverage.txt -o coverage.html
- go tool cover -func=coverage.txt
- curl -Os https://uploader.codecov.io/latest/linux/codecov
- chmod +x codecov
- ./codecov -t ${CODECOV_TOKEN} -R $CI_PROJECT_DIR -C $CI_COMMIT_SHA -r $CI_PROJECT_PATH
vulnerabilities:
stage: test
image: golang:1.21.5
script:
- go install golang.org/x/vuln/cmd/govulncheck@latest
- govulncheck ./...
prepare_release:
image: node:18
stage: prepare
before_script:
- npm install -g conventional-changelog-cli
script:
- conventional-changelog -p conventionalcommits > ./release.description
artifacts:
paths:
- coverage.html
- release.description
rules:
- if: $CI_COMMIT_TAG
release:
image: registry.gitlab.com/gitlab-org/release-cli:latest
stage: release
needs:
- job: prepare_release
artifacts: true
script:
- echo "Running release_job for $TAG"
release:
tag_name: '$CI_COMMIT_TAG'
description: ./release.description
rules:
- if: $CI_COMMIT_TAG
+13
View File
@@ -0,0 +1,13 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
version: 2
updates:
- package-ecosystem: "gomod"
directory: "/"
schedule:
interval: "daily"
open-pull-requests-limit: 20
rebase-strategy: none
+2
View File
@@ -0,0 +1,2 @@
run:
allow-parallel-runners: true
+42
View File
@@ -0,0 +1,42 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
args:
- --allow-multiple-documents
- id: check-added-large-files
- repo: https://gitlab.com/devopshq/gitlab-ci-linter
rev: v1.0.5
hooks:
- id: gitlab-ci-linter
args:
- --project
- unboundsoftware/shiny/authz_client
- repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook
rev: v9.5.0
hooks:
- id: commitlint
stages: [ commit-msg ]
additional_dependencies: [ '@commitlint/config-conventional' ]
- repo: https://github.com/dnephin/pre-commit-golang
rev: v0.5.1
hooks:
- id: go-mod-tidy
- id: go-imports
args:
- -local
- gitlab.com/unboundsoftware/shiny/authz_client
- repo: https://github.com/lietu/go-pre-commit
rev: v0.0.1
hooks:
- id: go-test
- id: gofumpt
- repo: https://github.com/golangci/golangci-lint
rev: v1.54.2
hooks:
- id: golangci-lint
+2 -1
View File
@@ -1,3 +1,4 @@
# Shiny authz-client
[![Build Status](https://gitlab.com/unboundsoftware/shiny/authz_client/badges/master/pipeline.svg)](https://gitlab.com/unboundsoftware/shiny/authz_client/commits/master)[![coverage report](https://gitlab.com/unboundsoftware/shiny/authz_client/badges/master/coverage.svg)](https://gitlab.com/unboundsoftware/shiny/authz_client/commits/master)
[![Build Status](https://gitlab.com/unboundsoftware/shiny/authz_client/badges/main/pipeline.svg)](https://gitlab.com/unboundsoftware/shiny/authz_client/commits/main)
[![codecov](https://codecov.io/gl/unboundsoftware:shiny/authz_client/branch/main/graph/badge.svg?token=AQS7QVLCEQ)](https://codecov.io/gl/unboundsoftware:shiny/authz_client)
+27 -8
View File
@@ -3,9 +3,12 @@ package client
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"reflect"
"sync"
"github.com/sparetimecoders/goamqp"
)
// CompanyPrivileges contains the privileges for a combination of email address and company id
@@ -21,6 +24,7 @@ type CompanyPrivileges struct {
// PrivilegeHandler processes PrivilegeAdded-events and fetches the initial set of privileges from an authz-service
type PrivilegeHandler struct {
*sync.RWMutex
client *http.Client
baseURL string
privileges map[string]map[string]*CompanyPrivileges
@@ -39,6 +43,7 @@ func WithBaseURL(url string) OptsFunc {
// New creates a new PrivilegeHandler. Pass OptsFuncs to configure.
func New(opts ...OptsFunc) *PrivilegeHandler {
handler := &PrivilegeHandler{
RWMutex: &sync.RWMutex{},
client: &http.Client{},
baseURL: "http://authz-service",
privileges: map[string]map[string]*CompanyPrivileges{},
@@ -56,11 +61,13 @@ func (h *PrivilegeHandler) Fetch() error {
return err
}
buff, err := ioutil.ReadAll(resp.Body)
buff, err := io.ReadAll(resp.Body)
if err != nil {
return err
}
h.RLock()
defer h.RUnlock()
err = json.Unmarshal(buff, &h.privileges)
if err != nil {
return err
@@ -69,31 +76,39 @@ func (h *PrivilegeHandler) Fetch() error {
}
// Process privilege-related events and update the internal state
func (h *PrivilegeHandler) Process(msg interface{}) bool {
func (h *PrivilegeHandler) Process(msg interface{}, _ goamqp.Headers) (interface{}, error) {
switch ev := msg.(type) {
case *UserAdded:
if priv, exists := h.privileges[ev.Email]; exists {
priv[ev.CompanyID] = &CompanyPrivileges{}
} else {
h.Lock()
defer h.Unlock()
h.privileges[ev.Email] = map[string]*CompanyPrivileges{
ev.CompanyID: {},
}
}
return true
return nil, nil
case *UserRemoved:
if priv, exists := h.privileges[ev.Email]; exists {
h.Lock()
defer h.Unlock()
delete(priv, ev.CompanyID)
}
return true
return nil, nil
case *PrivilegeAdded:
h.Lock()
defer h.Unlock()
h.setPrivileges(ev.Email, ev.CompanyID, ev.Privilege, true)
return true
return nil, nil
case *PrivilegeRemoved:
h.Lock()
defer h.Unlock()
h.setPrivileges(ev.Email, ev.CompanyID, ev.Privilege, false)
return true
return nil, nil
default:
fmt.Printf("Got unexpected message type (%s): '%+v'\n", reflect.TypeOf(msg).String(), msg)
return false
return nil, fmt.Errorf("unexpected event type: '%s'", reflect.TypeOf(msg))
}
}
@@ -128,6 +143,8 @@ func (h *PrivilegeHandler) setPrivileges(email, companyId string, privilege Priv
// CompaniesByUser return a slice of company ids matching the provided email and predicate func
func (h *PrivilegeHandler) CompaniesByUser(email string, predicate func(privileges CompanyPrivileges) bool) []string {
h.RLock()
defer h.RUnlock()
var result []string
if p, exists := h.privileges[email]; exists {
for k, v := range p {
@@ -141,6 +158,8 @@ func (h *PrivilegeHandler) CompaniesByUser(email string, predicate func(privileg
// IsAllowed return true if the provided predicate return true for the privileges matching the provided email and companyID, return false otherwise
func (h *PrivilegeHandler) IsAllowed(email, companyID string, predicate func(privileges CompanyPrivileges) bool) bool {
h.RLock()
defer h.RUnlock()
if p, exists := h.privileges[email]; exists {
if v, exists := p[companyID]; exists {
return predicate(*v)
+54 -41
View File
@@ -2,30 +2,34 @@ package client
import (
"fmt"
"github.com/stretchr/testify/assert"
"net/http"
"net/http/httptest"
"sort"
"testing"
"github.com/sparetimecoders/goamqp"
"github.com/stretchr/testify/assert"
)
func TestPrivilegeHandler_Process_InvalidType(t *testing.T) {
handler := New(WithBaseURL("base"))
result := handler.Process("abc")
result, err := handler.Process("abc", goamqp.Headers{})
assert.False(t, result)
assert.Nil(t, result)
assert.EqualError(t, err, "unexpected event type: 'string'")
}
func TestPrivilegeHandler_Process_PrivilegeRemoved(t *testing.T) {
handler := New(WithBaseURL("base"))
result := handler.Process(&PrivilegeAdded{
result, err := handler.Process(&PrivilegeAdded{
Email: "jim@example.org",
CompanyID: "abc-123",
Privilege: PrivilegeAdmin,
})
assert.True(t, result)
}, goamqp.Headers{})
assert.Nil(t, result)
assert.NoError(t, err)
companies := handler.CompaniesByUser("jim@example.org", func(privileges CompanyPrivileges) bool {
return privileges.Admin
@@ -33,12 +37,13 @@ func TestPrivilegeHandler_Process_PrivilegeRemoved(t *testing.T) {
assert.Equal(t, []string{"abc-123"}, companies)
result = handler.Process(&PrivilegeRemoved{
result, err = handler.Process(&PrivilegeRemoved{
Email: "jim@example.org",
CompanyID: "abc-123",
Privilege: PrivilegeAdmin,
})
assert.True(t, result)
}, goamqp.Headers{})
assert.Nil(t, result)
assert.NoError(t, err)
companies = handler.CompaniesByUser("jim@example.org", func(privileges CompanyPrivileges) bool {
return privileges.Admin
@@ -50,17 +55,19 @@ func TestPrivilegeHandler_Process_PrivilegeRemoved(t *testing.T) {
func TestPrivilegeHandler_Process_UserAdded_And_UserRemoved(t *testing.T) {
handler := New(WithBaseURL("base"))
result := handler.Process(&UserAdded{
result, err := handler.Process(&UserAdded{
Email: "jim@example.org",
CompanyID: "abc-123",
})
assert.True(t, result)
}, goamqp.Headers{})
assert.Nil(t, result)
assert.NoError(t, err)
result = handler.Process(&UserAdded{
result, err = handler.Process(&UserAdded{
Email: "jim@example.org",
CompanyID: "abc-456",
})
assert.True(t, result)
}, goamqp.Headers{})
assert.Nil(t, result)
assert.NoError(t, err)
companies := handler.CompaniesByUser("jim@example.org", func(privileges CompanyPrivileges) bool {
return true
@@ -68,17 +75,19 @@ func TestPrivilegeHandler_Process_UserAdded_And_UserRemoved(t *testing.T) {
sort.Strings(companies)
assert.Equal(t, []string{"abc-123", "abc-456"}, companies)
result = handler.Process(&UserRemoved{
result, err = handler.Process(&UserRemoved{
Email: "jim@example.org",
CompanyID: "abc-123",
})
assert.True(t, result)
}, goamqp.Headers{})
assert.Nil(t, result)
assert.NoError(t, err)
result = handler.Process(&UserRemoved{
result, err = handler.Process(&UserRemoved{
Email: "jim@example.org",
CompanyID: "abc-456",
})
assert.True(t, result)
}, goamqp.Headers{})
assert.Nil(t, result)
assert.NoError(t, err)
companies = handler.CompaniesByUser("jim@example.org", func(privileges CompanyPrivileges) bool {
return true
@@ -99,11 +108,12 @@ func TestPrivilegeHandler_GetCompanies_Email_Not_Found(t *testing.T) {
func TestPrivilegeHandler_GetCompanies_No_Companies_Found(t *testing.T) {
handler := New(WithBaseURL("base"))
result := handler.Process(&UserAdded{
result, err := handler.Process(&UserAdded{
Email: "jim@example.org",
CompanyID: "abc-123",
})
assert.True(t, result)
}, goamqp.Headers{})
assert.Nil(t, result)
assert.NoError(t, err)
companies := handler.CompaniesByUser("jim@example.org", func(privileges CompanyPrivileges) bool {
return privileges.Admin
@@ -117,11 +127,12 @@ func TestPrivilegeHandler_GetCompanies_No_Companies_Found(t *testing.T) {
assert.Equal(t, []string{"abc-123"}, companies)
result = handler.Process(&UserRemoved{
result, err = handler.Process(&UserRemoved{
Email: "jim@example.org",
CompanyID: "abc-123",
})
assert.True(t, result)
}, goamqp.Headers{})
assert.Nil(t, result)
assert.NoError(t, err)
companies = handler.CompaniesByUser("jim@example.org", func(privileges CompanyPrivileges) bool {
return true
@@ -132,12 +143,13 @@ func TestPrivilegeHandler_GetCompanies_No_Companies_Found(t *testing.T) {
func TestPrivilegeHandler_GetCompanies_Company_With_Company_Access_Found(t *testing.T) {
handler := New(WithBaseURL("base"))
result := handler.Process(&PrivilegeAdded{
result, err := handler.Process(&PrivilegeAdded{
Email: "jim@example.org",
CompanyID: "abc-123",
Privilege: PrivilegeCompany,
})
assert.True(t, result)
}, goamqp.Headers{})
assert.Nil(t, result)
assert.NoError(t, err)
companies := handler.CompaniesByUser("jim@example.org", func(privileges CompanyPrivileges) bool {
return privileges.Company
@@ -149,12 +161,13 @@ func TestPrivilegeHandler_GetCompanies_Company_With_Company_Access_Found(t *test
func TestPrivilegeHandler_GetCompanies_Company_With_Admin_Access_Found(t *testing.T) {
handler := New(WithBaseURL("base"))
result := handler.Process(&PrivilegeAdded{
result, err := handler.Process(&PrivilegeAdded{
Email: "jim@example.org",
CompanyID: "abc-123",
Privilege: PrivilegeConsumer,
})
assert.True(t, result)
}, goamqp.Headers{})
assert.Nil(t, result)
assert.NoError(t, err)
companies := handler.CompaniesByUser("jim@example.org", func(privileges CompanyPrivileges) bool {
return privileges.Consumer
@@ -176,11 +189,11 @@ func TestPrivilegeHandler_IsAllowed_Return_False_If_No_Privileges(t *testing.T)
func TestPrivilegeHandler_IsAllowed_Return_True_If_Privilege_Exists(t *testing.T) {
handler := New(WithBaseURL("base"))
handler.Process(&PrivilegeAdded{
_, _ = handler.Process(&PrivilegeAdded{
Email: "jim@example.org",
CompanyID: "abc-123",
Privilege: PrivilegeTime,
})
}, goamqp.Headers{})
result := handler.IsAllowed("jim@example.org", "abc-123", func(privileges CompanyPrivileges) bool {
return privileges.Time
@@ -188,11 +201,11 @@ func TestPrivilegeHandler_IsAllowed_Return_True_If_Privilege_Exists(t *testing.T
assert.True(t, result)
handler.Process(&PrivilegeAdded{
_, _ = handler.Process(&PrivilegeAdded{
Email: "jim@example.org",
CompanyID: "abc-123",
Privilege: PrivilegeInvoicing,
})
}, goamqp.Headers{})
result = handler.IsAllowed("jim@example.org", "abc-123", func(privileges CompanyPrivileges) bool {
return privileges.Invoicing
@@ -200,11 +213,11 @@ func TestPrivilegeHandler_IsAllowed_Return_True_If_Privilege_Exists(t *testing.T
assert.True(t, result)
handler.Process(&PrivilegeAdded{
_, _ = handler.Process(&PrivilegeAdded{
Email: "jim@example.org",
CompanyID: "abc-123",
Privilege: PrivilegeAccounting,
})
}, goamqp.Headers{})
result = handler.IsAllowed("jim@example.org", "abc-123", func(privileges CompanyPrivileges) bool {
return privileges.Accounting
@@ -212,11 +225,11 @@ func TestPrivilegeHandler_IsAllowed_Return_True_If_Privilege_Exists(t *testing.T
assert.True(t, result)
handler.Process(&PrivilegeAdded{
_, _ = handler.Process(&PrivilegeAdded{
Email: "jim@example.org",
CompanyID: "abc-123",
Privilege: PrivilegeSupplier,
})
}, goamqp.Headers{})
result = handler.IsAllowed("jim@example.org", "abc-123", func(privileges CompanyPrivileges) bool {
return privileges.Supplier
+14 -2
View File
@@ -1,5 +1,17 @@
module gitlab.com/unboundsoftware/shiny/authz_client
go 1.13
go 1.21
require github.com/stretchr/testify v1.4.0
require (
github.com/sparetimecoders/goamqp v0.2.1
github.com/stretchr/testify v1.8.4
)
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/google/uuid v1.5.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rabbitmq/amqp091-go v1.9.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
+27 -6
View File
@@ -1,11 +1,32 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU=
github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rabbitmq/amqp091-go v1.9.0 h1:qrQtyzB4H8BQgEuJwhmVQqVHB9O4+MNDJCCAcpc3Aoo=
github.com/rabbitmq/amqp091-go v1.9.0/go.mod h1:+jPrT9iY2eLjRaMSRHUhc3z14E/l85kv/f+6luSD3pc=
github.com/sparetimecoders/goamqp v0.2.1 h1:zW1zL3xzjzVx3+ftJtvBwDKAdI9mCM8a3mcGbwAAezc=
github.com/sparetimecoders/goamqp v0.2.1/go.mod h1:/kywWTiRX6EjLKG4eKmoO3l6byh4ycyeYjOx7csf3z4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A=
go.uber.org/goleak v1.2.1/go.mod h1:qlT2yGI9QafXHhZZLxlSuNsMw3FFLxBr+tBRlmO1xH4=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=