Files
kopia/internal/acl/access_level_test.go
Jarek Kowalski cbcd59f18e Added repository user authorization support + server flag refactoring + refresh (#890)
* nit: replaced harcoded string constants with named constants

* acl: added management of ACL entries

* auth: implemented DefaultAuthorizer which uses ACLs if any entries are found in the system and falls back to LegacyAuthorizer if not

* cli: switch to DefaultAuthorizer when starting server

* cli: added ACL management

* server: refactored authenticator + added refresh

Authenticator is now an interface which also supports Refresh.

* authz: refactored authorizer to be an interface + added Refresh()

* server: refresh authentication and authorizer

* e2e tests for ACLs

* server: handling of SIGHUP to refresh authn/authz caches

* server: reorganized flags to specify auth options:

- removed '--allow-repository-users' - it's always on
- one of --without-password, --server-password or --random-password
  can be specified to specify password for the UI user
- htpasswd-file - can be specified to provide password for UI or remote
  users

* cli: moved 'kopia user' to 'kopia server user'

* server: allow all UI actions if no authenticator is set

* acl: removed priority until we have a better understood use case for it

* acl: added validation of allowed labels when adding ACL entries

* site: added docs for ACLs
2021-03-18 23:03:27 -07:00

50 lines
877 B
Go

package acl_test
import (
"encoding/json"
"testing"
"github.com/google/go-cmp/cmp"
"github.com/kopia/kopia/internal/acl"
)
func TestAccessLevelJSONSerialization(t *testing.T) {
var s1, s2 struct {
B acl.AccessLevel `json:"b"`
C acl.AccessLevel `json:"c"`
D acl.AccessLevel `json:"d"`
E acl.AccessLevel `json:"e"`
}
s1.B = acl.AccessLevelNone
s1.C = acl.AccessLevelRead
s1.D = acl.AccessLevelAppend
s1.E = acl.AccessLevelFull
v, err := json.MarshalIndent(s1, "", " ")
if err != nil {
t.Fatal(err)
}
got := string(v)
want := `{
"b": "NONE",
"c": "READ",
"d": "APPEND",
"e": "FULL"
}`
if diff := cmp.Diff(got, want); diff != "" {
t.Fatalf("diff: (-got, +want): %v", diff)
}
if err := json.Unmarshal(v, &s2); err != nil {
t.Fatal(err)
}
if diff := cmp.Diff(s1, s2); diff != "" {
t.Fatalf("diff: (-got, +want): %v", diff)
}
}