From 1c907281bf0340803f8a919f9a40f69df3ad1480 Mon Sep 17 00:00:00 2001 From: Samir Patel <48686912+54mir@users.noreply.github.com> Date: Mon, 20 Dec 2021 18:03:18 -0600 Subject: [PATCH] authz changes --- authz/authorization_test.go | 25 +++++++++++++------------ server/config.go | 9 +++------ server/config_internal_test.go | 13 ++++++------- 3 files changed, 22 insertions(+), 25 deletions(-) diff --git a/authz/authorization_test.go b/authz/authorization_test.go index dab33dbe1..45718fe29 100644 --- a/authz/authorization_test.go +++ b/authz/authorization_test.go @@ -20,6 +20,7 @@ import ( "strings" "testing" + "github.com/molecula/featurebase/v2/authn" "github.com/molecula/featurebase/v2/authz" ) @@ -107,17 +108,17 @@ admin: "ac97c9e2-346b-42a2-b6da-18bcb61a32fe"` // initializes groups that are returned from identity provider groupName := "name" userId := "user-id" - groupsList1 := []authz.Group{} - groupsList2 := []authz.Group{{userId, "fake-group", groupName}} - groupsList3 := []authz.Group{ + groupsList1 := []authn.Group{} + groupsList2 := []authn.Group{{userId, "fake-group", groupName}} + groupsList3 := []authn.Group{ {userId, "dca35310-ecda-4f23-86cd-876aee55906b", groupName}, {userId, "dca35310-ecda-4f23-86cd-876aee559900", groupName}, } - groupsList4 := []authz.Group{{userId, "ac97c9e2-346b-42a2-b6da-18bcb61a32fe", groupName}} + groupsList4 := []authn.Group{{userId, "ac97c9e2-346b-42a2-b6da-18bcb61a32fe", groupName}} tests := []struct { yamlData string - groups []authz.Group + groups []authn.Group index string userAccess string err string @@ -201,11 +202,11 @@ admin: "ac97c9e2-346b-42a2-b6da-18bcb61a32fe"` func TestAuth_IsAdmin(t *testing.T) { - group1 := []authz.Group{ + group1 := []authn.Group{ {"admin-user-id", "ac97c9e2-346b-42a2-b6da-18bcb61a32fe", "admin-group"}, } - group2 := []authz.Group{ + group2 := []authn.Group{ {"user-id", "dca35310-ecda-4f23-86cd-876aee55906b", "group-name"}, } @@ -217,7 +218,7 @@ func TestAuth_IsAdmin(t *testing.T) { } tests := []struct { - groups []authz.Group + groups []authn.Group groupPermissions authz.GroupPermissions output bool }{ @@ -242,15 +243,15 @@ func TestAuth_IsAdmin(t *testing.T) { func TestAuth_GetAuthorizedIndexList(t *testing.T) { - group1 := []authz.Group{ + group1 := []authn.Group{ {"user-id", "dca35310-ecda-4f23-86cd-876aee55906b", "group-name"}, } - group2 := []authz.Group{ + group2 := []authn.Group{ {"admin-user-id", "ac97c9e2-346b-42a2-b6da-18bcb61a32fe", "admin-group"}, } - group3 := []authz.Group{ + group3 := []authn.Group{ {"user-id", "dca35310-ecda-4f23-86cd-876aee559900", "group-name"}, } @@ -268,7 +269,7 @@ func TestAuth_GetAuthorizedIndexList(t *testing.T) { } tests := []struct { - groups []authz.Group + groups []authn.Group permission string output []string }{ diff --git a/server/config.go b/server/config.go index 95eabd727..a551f65b3 100644 --- a/server/config.go +++ b/server/config.go @@ -15,7 +15,6 @@ import ( "strings" "time" - "github.com/molecula/featurebase/v2/authz" petcd "github.com/molecula/featurebase/v2/etcd" rbfcfg "github.com/molecula/featurebase/v2/rbf/cfg" @@ -234,15 +233,14 @@ type Config struct { // Toggles /schema/details endpoint. If off, it returns empty. SchemaDetailsOn bool `toml:"schema-details-on"` - Auth Auth } type Auth struct { // Enable AuthZ/AuthN for featurebase server Enable bool `toml:"enable"` - - ClientId string `toml:"client-id"` + + ClientId string `toml:"client-id"` ClientSecret string `toml:"client-secret"` AuthorizeURL string `toml:"authorize-url"` TokenURL string `toml:"token-url"` @@ -251,8 +249,7 @@ type Auth struct { Scopes []string `toml:"scopes"` HashKey string `toml:"hash-key"` BlockKey string `toml:"block-key"` - PermissionsFile string `toml:"permissions"` - Auth authz.Auth `toml:"auth"` + PermissionsFile string `toml:"permissions"` } // Namespace returns the namespace to use based on the Future flag. diff --git a/server/config_internal_test.go b/server/config_internal_test.go index 0d5c17778..4af9007fe 100644 --- a/server/config_internal_test.go +++ b/server/config_internal_test.go @@ -8,7 +8,6 @@ import ( "os" "strings" "testing" - "github.com/molecula/featurebase/v2/authz" ) type addrs struct{ bind, advertise string } @@ -281,7 +280,7 @@ func TestConfig_validateAuth(t *testing.T) { errorMesgEmpty := "empty string" errorMesgURL := "invalid URL" errorMesgScope := "must provide scope" - errorMesgKey := "invalid key length" + errorMesgKey := "invalid key length" validTestURL := "https://url.com/" validClientID := "clientid" validClientSecret := "clientSecret" @@ -366,8 +365,8 @@ func TestConfig_validateAuth(t *testing.T) { { // Auth enabled, all configs are set properly except scope []string{ - errorMesgScope, - }, + errorMesgScope, + }, Auth{ Enable: enable, ClientId: validClientID, @@ -433,9 +432,9 @@ func TestConfig_validateAuth(t *testing.T) { } for i, e := range errors { - if !strings.Contains(e.Error(), test.expErrs[i]) { - t.Errorf("expected error to contain %s, but got %s", test.expErrs[i], e.Error()) - } + if !strings.Contains(e.Error(), test.expErrs[i]) { + t.Errorf("expected error to contain %s, but got %s", test.expErrs[i], e.Error()) + } } }) }