@@ -14,6 +14,12 @@ func TestLoadWithEnvOverrides(t *testing.T) {
1414 t .Setenv ("AUTH_AUDIENCE" , "nist-api" )
1515 t .Setenv ("AUTH_JWKS_URL" , "https://issuer.example.com/jwks.json" )
1616 t .Setenv ("AUTH_TOKEN_TYPE" , "jwt" )
17+ t .Setenv ("AUTHZ_REQUIRED_ROLES" , "NIST_ROLE, entropy-admin " )
18+ t .Setenv ("AUTHZ_REQUIRED_SCOPES" , "openid, profile" )
19+ t .Setenv ("AUTHZ_ROLE_MATCH_MODE" , "all" )
20+ t .Setenv ("AUTHZ_SCOPE_MATCH_MODE" , "any" )
21+ t .Setenv ("AUTHZ_ROLE_CLAIM_PATHS" , "roles,urn:zitadel:iam:org:project:roles" )
22+ t .Setenv ("AUTHZ_SCOPE_CLAIM_PATHS" , "scope,scp" )
1723 t .Setenv ("TLS_ENABLED" , "true" )
1824 t .Setenv ("TLS_CERT_FILE" , "/tmp/cert.pem" )
1925 t .Setenv ("TLS_KEY_FILE" , "/tmp/key.pem" )
@@ -47,6 +53,24 @@ func TestLoadWithEnvOverrides(t *testing.T) {
4753 if cfg .AuthTokenType != "jwt" {
4854 t .Fatalf ("unexpected auth token type: %s" , cfg .AuthTokenType )
4955 }
56+ if len (cfg .AuthzRequiredRoles ) != 2 || cfg .AuthzRequiredRoles [0 ] != "NIST_ROLE" || cfg .AuthzRequiredRoles [1 ] != "entropy-admin" {
57+ t .Fatalf ("unexpected authz required roles: %#v" , cfg .AuthzRequiredRoles )
58+ }
59+ if len (cfg .AuthzRequiredScopes ) != 2 || cfg .AuthzRequiredScopes [0 ] != "openid" || cfg .AuthzRequiredScopes [1 ] != "profile" {
60+ t .Fatalf ("unexpected authz required scopes: %#v" , cfg .AuthzRequiredScopes )
61+ }
62+ if cfg .AuthzRoleMatchMode != "all" {
63+ t .Fatalf ("unexpected authz role match mode: %s" , cfg .AuthzRoleMatchMode )
64+ }
65+ if cfg .AuthzScopeMatchMode != "any" {
66+ t .Fatalf ("unexpected authz scope match mode: %s" , cfg .AuthzScopeMatchMode )
67+ }
68+ if len (cfg .AuthzRoleClaimPaths ) != 2 || cfg .AuthzRoleClaimPaths [0 ] != "roles" || cfg .AuthzRoleClaimPaths [1 ] != "urn:zitadel:iam:org:project:roles" {
69+ t .Fatalf ("unexpected authz role claim paths: %#v" , cfg .AuthzRoleClaimPaths )
70+ }
71+ if len (cfg .AuthzScopeClaimPaths ) != 2 || cfg .AuthzScopeClaimPaths [0 ] != "scope" || cfg .AuthzScopeClaimPaths [1 ] != "scp" {
72+ t .Fatalf ("unexpected authz scope claim paths: %#v" , cfg .AuthzScopeClaimPaths )
73+ }
5074 if ! cfg .TLSEnabled {
5175 t .Fatalf ("expected TLSEnabled to be true" )
5276 }
@@ -196,6 +220,8 @@ func TestValidateFailures(t *testing.T) {
196220 {"auth opaque private key jwt missing private key" , Config {GRPCPort : 9000 , MetricsPort : 9001 , LogLevel : "info" , AuthEnabled : true , AuthIssuer : "https://issuer.example.com" , AuthAudience : "api" , AuthTokenType : "opaque" , AuthIntrospectionURL : "https://issuer.example.com/oauth2/introspect" , AuthIntrospectionAuthMethod : "private_key_jwt" }},
197221 {"auth opaque private key jwt both inline and file set" , Config {GRPCPort : 9000 , MetricsPort : 9001 , LogLevel : "info" , AuthEnabled : true , AuthIssuer : "https://issuer.example.com" , AuthAudience : "api" , AuthTokenType : "opaque" , AuthIntrospectionURL : "https://issuer.example.com/oauth2/introspect" , AuthIntrospectionAuthMethod : "private_key_jwt" , AuthIntrospectionPrivateKey : "PEM" , AuthIntrospectionPrivateKeyFile : "/tmp/key.json" }},
198222 {"auth opaque private key jwt invalid algorithm" , Config {GRPCPort : 9000 , MetricsPort : 9001 , LogLevel : "info" , AuthEnabled : true , AuthIssuer : "https://issuer.example.com" , AuthAudience : "api" , AuthTokenType : "opaque" , AuthIntrospectionURL : "https://issuer.example.com/oauth2/introspect" , AuthIntrospectionAuthMethod : "private_key_jwt" , AuthIntrospectionPrivateKey : "PEM" , AuthIntrospectionPrivateKeyJWTAlgorithm : "PS256" }},
223+ {"authz invalid role match mode" , Config {GRPCPort : 9000 , MetricsPort : 9001 , LogLevel : "info" , AuthzRoleMatchMode : "one" }},
224+ {"authz invalid scope match mode" , Config {GRPCPort : 9000 , MetricsPort : 9001 , LogLevel : "info" , AuthzScopeMatchMode : "one" }},
199225 {"tls enabled missing cert" , Config {GRPCPort : 9000 , MetricsPort : 9001 , LogLevel : "info" , TLSEnabled : true , TLSKeyFile : "/tmp/key.pem" }},
200226 {"tls enabled missing key" , Config {GRPCPort : 9000 , MetricsPort : 9001 , LogLevel : "info" , TLSEnabled : true , TLSCertFile : "/tmp/cert.pem" }},
201227 {"tls enabled invalid client auth" , Config {GRPCPort : 9000 , MetricsPort : 9001 , LogLevel : "info" , TLSEnabled : true , TLSCertFile : "/tmp/cert.pem" , TLSKeyFile : "/tmp/key.pem" , TLSClientAuth : "invalid" }},
@@ -269,6 +295,8 @@ func TestLoadDefaults(t *testing.T) {
269295 "AUTH_INTROSPECTION_URL" , "AUTH_INTROSPECTION_AUTH_METHOD" , "AUTH_INTROSPECTION_CLIENT_ID" , "AUTH_INTROSPECTION_CLIENT_SECRET" ,
270296 "AUTH_INTROSPECTION_PRIVATE_KEY" , "AUTH_INTROSPECTION_PRIVATE_KEY_FILE" ,
271297 "AUTH_INTROSPECTION_PRIVATE_KEY_JWT_KID" , "AUTH_INTROSPECTION_PRIVATE_KEY_JWT_ALG" ,
298+ "AUTHZ_REQUIRED_ROLES" , "AUTHZ_REQUIRED_SCOPES" , "AUTHZ_ROLE_MATCH_MODE" , "AUTHZ_SCOPE_MATCH_MODE" ,
299+ "AUTHZ_ROLE_CLAIM_PATHS" , "AUTHZ_SCOPE_CLAIM_PATHS" ,
272300 "TLS_ENABLED" , "TLS_CERT_FILE" , "TLS_KEY_FILE" , "TLS_CA_FILE" , "TLS_CLIENT_AUTH" , "TLS_MIN_VERSION" ,
273301 } {
274302 t .Setenv (key , "" )
@@ -295,6 +323,15 @@ func TestLoadDefaults(t *testing.T) {
295323 if cfg .AuthIssuer != "" || cfg .AuthAudience != "" || cfg .AuthJWKSURL != "" || cfg .AuthIntrospectionURL != "" || cfg .AuthIntrospectionClientID != "" || cfg .AuthIntrospectionClientSecret != "" || cfg .AuthIntrospectionPrivateKey != "" || cfg .AuthIntrospectionPrivateKeyFile != "" || cfg .AuthIntrospectionPrivateKeyJWTKeyID != "" || cfg .AuthIntrospectionPrivateKeyJWTAlgorithm != "" {
296324 t .Errorf ("expected auth config defaults to be empty, got %+v" , cfg )
297325 }
326+ if len (cfg .AuthzRequiredRoles ) != 0 || len (cfg .AuthzRequiredScopes ) != 0 || len (cfg .AuthzRoleClaimPaths ) != 0 || len (cfg .AuthzScopeClaimPaths ) != 0 {
327+ t .Errorf ("expected authz list defaults to be empty, got %+v" , cfg )
328+ }
329+ if cfg .AuthzRoleMatchMode != "any" {
330+ t .Errorf ("expected AuthzRoleMatchMode to default to 'any', got %s" , cfg .AuthzRoleMatchMode )
331+ }
332+ if cfg .AuthzScopeMatchMode != "any" {
333+ t .Errorf ("expected AuthzScopeMatchMode to default to 'any', got %s" , cfg .AuthzScopeMatchMode )
334+ }
298335 if cfg .AuthTokenType != "jwt" {
299336 t .Errorf ("expected AuthTokenType to default to 'jwt', got %s" , cfg .AuthTokenType )
300337 }
0 commit comments