@ -216,6 +216,7 @@ func TestStateStore_ACLBootstrap(t *testing.T) {
require . Equal ( t , uint64 ( 3 ) , index )
// Make sure the ACLs are in an expected state.
// nolint:staticcheck
_ , tokens , err := s . ACLTokenList ( nil , true , true , "" , "" , "" , nil , nil )
require . NoError ( t , err )
require . Len ( t , tokens , 1 )
@ -230,6 +231,7 @@ func TestStateStore_ACLBootstrap(t *testing.T) {
err = s . ACLBootstrap ( 32 , index , token2 . Clone ( ) )
require . NoError ( t , err )
// nolint:staticcheck
_ , tokens , err = s . ACLTokenList ( nil , true , true , "" , "" , "" , nil , nil )
require . NoError ( t , err )
require . Len ( t , tokens , 2 )
@ -957,18 +959,36 @@ func TestStateStore_ACLToken_List(t *testing.T) {
AuthMethod : "test" ,
Local : true ,
} ,
// the serviceName specific token
& structs . ACLToken {
AccessorID : "80c900e1-2fc5-4685-ae29-1b2d17fc30e4" ,
SecretID : "9d229cfd-ec4b-4d31-a6fd-ecbcb2a41d41" ,
ServiceIdentities : [ ] * structs . ACLServiceIdentity {
{ ServiceName : "sn1" } ,
} ,
} ,
// the serviceName specific token and local
& structs . ACLToken {
AccessorID : "a14fa45e-0afe-4b44-961d-a430030ccfe2" ,
SecretID : "17f696b9-448a-4bd3-936b-08c92c66530f" ,
ServiceIdentities : [ ] * structs . ACLServiceIdentity {
{ ServiceName : "sn1" } ,
} ,
Local : true ,
} ,
}
require . NoError ( t , s . ACLTokenBatchSet ( 2 , tokens , ACLTokenSetOptions { } ) )
type testCase struct {
name string
local bool
global bool
policy string
role string
methodName string
accessors [ ] string
name string
local bool
global bool
policy string
role string
methodName string
serviceName string
accessors [ ] string
}
cases := [ ] testCase {
@ -984,6 +1004,7 @@ func TestStateStore_ACLToken_List(t *testing.T) {
"47eea4da-bda1-48a6-901c-3e36d2d9262f" , // policy + global
"54866514-3cf2-4fec-8a8a-710583831834" , // mgmt + global
"74277ae1-6a9b-4035-b444-2370fe6a2cb5" , // authMethod + global
"80c900e1-2fc5-4685-ae29-1b2d17fc30e4" , // serviceName + global
"a7715fde-8954-4c92-afbc-d84c6ecdc582" , // role + global
} ,
} ,
@ -997,6 +1018,7 @@ func TestStateStore_ACLToken_List(t *testing.T) {
accessors : [ ] string {
"211f0360-ef53-41d3-9d4d-db84396eb6c0" , // authMethod + local
"4915fc9d-3726-4171-b588-6c271f45eecd" , // policy + local
"a14fa45e-0afe-4b44-961d-a430030ccfe2" , // serviceName + local
"cadb4f13-f62a-49ab-ab3f-5a7e01b925d9" , // role + local
"f1093997-b6c7-496d-bfb8-6b1b1895641b" , // mgmt + local
} ,
@ -1091,6 +1113,30 @@ func TestStateStore_ACLToken_List(t *testing.T) {
"74277ae1-6a9b-4035-b444-2370fe6a2cb5" , // authMethod + global
} ,
} ,
{
name : "ServiceName - Local" ,
local : true ,
global : false ,
policy : "" ,
role : "" ,
methodName : "" ,
serviceName : "sn1" ,
accessors : [ ] string {
"a14fa45e-0afe-4b44-961d-a430030ccfe2" , // serviceName + local
} ,
} ,
{
name : "ServiceName - Global" ,
local : false ,
global : true ,
policy : "" ,
role : "" ,
methodName : "" ,
serviceName : "sn1" ,
accessors : [ ] string {
"80c900e1-2fc5-4685-ae29-1b2d17fc30e4" , // serviceName + global
} ,
} ,
{
name : "All" ,
local : true ,
@ -1105,6 +1151,8 @@ func TestStateStore_ACLToken_List(t *testing.T) {
"4915fc9d-3726-4171-b588-6c271f45eecd" , // policy + local
"54866514-3cf2-4fec-8a8a-710583831834" , // mgmt + global
"74277ae1-6a9b-4035-b444-2370fe6a2cb5" , // authMethod + global
"80c900e1-2fc5-4685-ae29-1b2d17fc30e4" , // serviceName + global
"a14fa45e-0afe-4b44-961d-a430030ccfe2" , // serviceName + local
"a7715fde-8954-4c92-afbc-d84c6ecdc582" , // role + global
"cadb4f13-f62a-49ab-ab3f-5a7e01b925d9" , // role + local
"f1093997-b6c7-496d-bfb8-6b1b1895641b" , // mgmt + local
@ -1112,14 +1160,27 @@ func TestStateStore_ACLToken_List(t *testing.T) {
} ,
}
for _ , tc := range [ ] struct { policy , role , methodName string } {
{ testPolicyID_A , testRoleID_A , "test" } ,
{ "" , testRoleID_A , "test" } ,
{ testPolicyID_A , "" , "test" } ,
{ testPolicyID_A , testRoleID_A , "" } ,
for _ , tc := range [ ] struct { policy , role , methodName , serviceName string } {
{ testPolicyID_A , testRoleID_A , "test" , "" } ,
{ "" , testRoleID_A , "test" , "" } ,
{ testPolicyID_A , "" , "test" , "" } ,
{ testPolicyID_A , testRoleID_A , "" , "" } ,
{ testPolicyID_A , "" , "" , "test" } ,
} {
t . Run ( fmt . Sprintf ( "can't filter on more than one: %s/%s/%s" , tc . policy , tc . role , tc . methodName ) , func ( t * testing . T ) {
_ , _ , err := s . ACLTokenList ( nil , false , false , tc . policy , tc . role , tc . methodName , nil , nil )
t . Run ( fmt . Sprintf ( "can't filter on more than one: %s/%s/%s/%s" , tc . policy , tc . role , tc . methodName , tc . serviceName ) , func ( t * testing . T ) {
var err error
if tc . serviceName == "" {
// The legacy call can only be tested when the serviceName is not specified
// nolint:staticcheck
_ , _ , err = s . ACLTokenList ( nil , false , false , tc . policy , tc . role , tc . methodName , nil , nil )
require . Error ( t , err )
}
_ , _ , err = s . ACLTokenListWithParameters ( nil , ACLTokenListParameters {
Policy : tc . policy ,
Role : tc . role ,
MethodName : tc . methodName ,
ServiceName : tc . serviceName ,
} )
require . Error ( t , err )
} )
}
@ -1128,12 +1189,33 @@ func TestStateStore_ACLToken_List(t *testing.T) {
tc := tc // capture range variable
t . Run ( tc . name , func ( t * testing . T ) {
t . Parallel ( )
_ , tokens , err := s . ACLTokenList ( nil , tc . local , tc . global , tc . policy , tc . role , tc . methodName , nil , nil )
require . NoError ( t , err )
require . Len ( t , tokens , len ( tc . accessors ) )
tokens . Sort ( )
for i , token := range tokens {
require . Equal ( t , tc . accessors [ i ] , token . AccessorID )
// Test old function
if tc . serviceName == "" {
// nolint:staticcheck
_ , tokens , err := s . ACLTokenList ( nil , tc . local , tc . global , tc . policy , tc . role , tc . methodName , nil , nil )
require . NoError ( t , err )
require . Len ( t , tokens , len ( tc . accessors ) )
tokens . Sort ( )
for i , token := range tokens {
require . Equal ( t , tc . accessors [ i ] , token . AccessorID )
}
}
// Test new function
{
_ , tokens , err := s . ACLTokenListWithParameters ( nil , ACLTokenListParameters {
Local : tc . local ,
Global : tc . global ,
Policy : tc . policy ,
Role : tc . role ,
ServiceName : tc . serviceName ,
MethodName : tc . methodName ,
} )
require . NoError ( t , err )
require . Len ( t , tokens , len ( tc . accessors ) )
tokens . Sort ( )
for i , token := range tokens {
require . Equal ( t , tc . accessors [ i ] , token . AccessorID )
}
}
} )
}
@ -1189,6 +1271,7 @@ func TestStateStore_ACLToken_FixupPolicyLinks(t *testing.T) {
require . Equal ( t , "node-read-renamed" , retrieved . Policies [ 0 ] . Name )
// list tokens without stale links
// nolint:staticcheck
_ , tokens , err := s . ACLTokenList ( nil , true , true , "" , "" , "" , nil , nil )
require . NoError ( t , err )
@ -1233,6 +1316,7 @@ func TestStateStore_ACLToken_FixupPolicyLinks(t *testing.T) {
require . Len ( t , retrieved . Policies , 0 )
// list tokens without stale links
// nolint:staticcheck
_ , tokens , err = s . ACLTokenList ( nil , true , true , "" , "" , "" , nil , nil )
require . NoError ( t , err )
@ -1318,6 +1402,7 @@ func TestStateStore_ACLToken_FixupRoleLinks(t *testing.T) {
require . Equal ( t , "node-read-role-renamed" , retrieved . Roles [ 0 ] . Name )
// list tokens without stale links
// nolint:staticcheck
_ , tokens , err := s . ACLTokenList ( nil , true , true , "" , "" , "" , nil , nil )
require . NoError ( t , err )
@ -1362,6 +1447,7 @@ func TestStateStore_ACLToken_FixupRoleLinks(t *testing.T) {
require . Len ( t , retrieved . Roles , 0 )
// list tokens without stale links
// nolint:staticcheck
_ , tokens , err = s . ACLTokenList ( nil , true , true , "" , "" , "" , nil , nil )
require . NoError ( t , err )
@ -2802,16 +2888,19 @@ func TestStateStore_ACLAuthMethod_GlobalNameShadowing_TokenTest(t *testing.T) {
}
require . True ( t , t . Run ( "list local only" , func ( t * testing . T ) {
// nolint:staticcheck
_ , got , err := s . ACLTokenList ( nil , true , false , "" , "" , "test" , defaultEntMeta , defaultEntMeta )
require . NoError ( t , err )
require . ElementsMatch ( t , [ ] string { methodDC2_tok1 , methodDC2_tok2 } , toList ( got ) )
} ) )
require . True ( t , t . Run ( "list global only" , func ( t * testing . T ) {
// nolint:staticcheck
_ , got , err := s . ACLTokenList ( nil , false , true , "" , "" , "test" , defaultEntMeta , defaultEntMeta )
require . NoError ( t , err )
require . ElementsMatch ( t , [ ] string { methodDC1_tok1 , methodDC1_tok2 } , toList ( got ) )
} ) )
require . True ( t , t . Run ( "list both" , func ( t * testing . T ) {
// nolint:staticcheck
_ , got , err := s . ACLTokenList ( nil , true , true , "" , "" , "test" , defaultEntMeta , defaultEntMeta )
require . NoError ( t , err )
require . ElementsMatch ( t , [ ] string { methodDC1_tok1 , methodDC1_tok2 , methodDC2_tok1 , methodDC2_tok2 } , toList ( got ) )
@ -2823,16 +2912,19 @@ func TestStateStore_ACLAuthMethod_GlobalNameShadowing_TokenTest(t *testing.T) {
} ) )
require . True ( t , t . Run ( "list local only (after dc2 delete)" , func ( t * testing . T ) {
// nolint:staticcheck
_ , got , err := s . ACLTokenList ( nil , true , false , "" , "" , "test" , defaultEntMeta , defaultEntMeta )
require . NoError ( t , err )
require . Empty ( t , got )
} ) )
require . True ( t , t . Run ( "list global only (after dc2 delete)" , func ( t * testing . T ) {
// nolint:staticcheck
_ , got , err := s . ACLTokenList ( nil , false , true , "" , "" , "test" , defaultEntMeta , defaultEntMeta )
require . NoError ( t , err )
require . ElementsMatch ( t , [ ] string { methodDC1_tok1 , methodDC1_tok2 } , toList ( got ) )
} ) )
require . True ( t , t . Run ( "list both (after dc2 delete)" , func ( t * testing . T ) {
// nolint:staticcheck
_ , got , err := s . ACLTokenList ( nil , true , true , "" , "" , "test" , defaultEntMeta , defaultEntMeta )
require . NoError ( t , err )
require . ElementsMatch ( t , [ ] string { methodDC1_tok1 , methodDC1_tok2 } , toList ( got ) )
@ -3625,6 +3717,7 @@ func TestStateStore_ACLTokens_Snapshot_Restore(t *testing.T) {
require . NoError ( t , s . ACLRoleBatchSet ( 2 , roles , false ) )
// Read the restored ACLs back out and verify that they match.
// nolint:staticcheck
idx , res , err := s . ACLTokenList ( nil , true , true , "" , "" , "" , nil , nil )
require . NoError ( t , err )
require . Equal ( t , uint64 ( 4 ) , idx )