@ -74,252 +74,6 @@ func TestACLEndpoint_BootstrapTokens(t *testing.T) {
require . Equal ( t , out . CreateIndex , out . ModifyIndex )
}
func TestACLEndpoint_Apply ( t * testing . T ) {
if testing . Short ( ) {
t . Skip ( "too slow for testing.Short" )
}
t . Parallel ( )
_ , srv , codec := testACLServerWithConfig ( t , nil , false )
waitForLeaderEstablishment ( t , srv )
arg := structs . ACLRequest {
Datacenter : "dc1" ,
Op : structs . ACLSet ,
ACL : structs . ACL {
Name : "User token" ,
Type : structs . ACLTokenTypeClient ,
} ,
WriteRequest : structs . WriteRequest { Token : TestDefaultMasterToken } ,
}
var out string
err := msgpackrpc . CallWithCodec ( codec , "ACL.Apply" , & arg , & out )
require . NoError ( t , err )
id := out
// Verify
state := srv . fsm . State ( )
_ , s , err := state . ACLTokenGetBySecret ( nil , out , nil )
require . NoError ( t , err )
require . NotNil ( t , s )
require . Equal ( t , out , s . SecretID )
require . Equal ( t , "User token" , s . Description )
// Do a delete
arg . Op = structs . ACLDelete
arg . ACL . ID = out
err = msgpackrpc . CallWithCodec ( codec , "ACL.Apply" , & arg , & out )
require . NoError ( t , err )
// Verify
_ , s , err = state . ACLTokenGetBySecret ( nil , id , nil )
require . NoError ( t , err )
require . Nil ( t , s )
}
func TestACLEndpoint_Update_PurgeCache ( t * testing . T ) {
if testing . Short ( ) {
t . Skip ( "too slow for testing.Short" )
}
t . Parallel ( )
_ , srv , codec := testACLServerWithConfig ( t , nil , false )
waitForLeaderEstablishment ( t , srv )
arg := structs . ACLRequest {
Datacenter : "dc1" ,
Op : structs . ACLSet ,
ACL : structs . ACL {
Name : "User token" ,
Type : structs . ACLTokenTypeClient ,
Rules : ` key "" { policy = "read"} ` ,
} ,
WriteRequest : structs . WriteRequest { Token : TestDefaultMasterToken } ,
}
var out string
err := msgpackrpc . CallWithCodec ( codec , "ACL.Apply" , & arg , & out )
require . NoError ( t , err )
id := out
// Resolve
acl1 , err := srv . ResolveToken ( id )
require . NoError ( t , err )
require . NotNil ( t , acl1 )
require . Equal ( t , acl . Allow , acl1 . KeyRead ( "foo" , nil ) )
// Do an update
arg . ACL . ID = out
arg . ACL . Rules = ` { "key": { "": { "policy": "deny"}}} `
err = msgpackrpc . CallWithCodec ( codec , "ACL.Apply" , & arg , & out )
require . NoError ( t , err )
// Resolve again
acl2 , err := srv . ResolveToken ( id )
require . NoError ( t , err )
require . NotNil ( t , acl2 )
require . NotSame ( t , acl2 , acl1 )
require . NotEqual ( t , acl . Allow , acl2 . KeyRead ( "foo" , nil ) )
// Do a delete
arg . Op = structs . ACLDelete
arg . ACL . Rules = ""
err = msgpackrpc . CallWithCodec ( codec , "ACL.Apply" , & arg , & out )
require . NoError ( t , err )
// Resolve again
acl3 , err := srv . ResolveToken ( id )
require . True ( t , acl . IsErrNotFound ( err ) , "Error %v is not acl.ErrNotFound" , err )
require . Nil ( t , acl3 )
}
func TestACLEndpoint_Apply_CustomID ( t * testing . T ) {
if testing . Short ( ) {
t . Skip ( "too slow for testing.Short" )
}
t . Parallel ( )
_ , srv , codec := testACLServerWithConfig ( t , nil , false )
waitForLeaderEstablishment ( t , srv )
arg := structs . ACLRequest {
Datacenter : "dc1" ,
Op : structs . ACLSet ,
ACL : structs . ACL {
ID : "foobarbaz" , // Specify custom ID, does not exist
Name : "User token" ,
Type : structs . ACLTokenTypeClient ,
} ,
WriteRequest : structs . WriteRequest { Token : TestDefaultMasterToken } ,
}
var out string
err := msgpackrpc . CallWithCodec ( codec , "ACL.Apply" , & arg , & out )
require . NoError ( t , err )
require . Equal ( t , "foobarbaz" , out )
// Verify
state := srv . fsm . State ( )
_ , s , err := state . ACLTokenGetBySecret ( nil , out , nil )
require . NoError ( t , err )
require . NotNil ( t , s )
require . Equal ( t , out , s . SecretID )
require . Equal ( t , "User token" , s . Description )
}
func TestACLEndpoint_Apply_Denied ( t * testing . T ) {
if testing . Short ( ) {
t . Skip ( "too slow for testing.Short" )
}
t . Parallel ( )
_ , srv , codec := testACLServerWithConfig ( t , nil , false )
waitForLeaderEstablishment ( t , srv )
arg := structs . ACLRequest {
Datacenter : "dc1" ,
Op : structs . ACLSet ,
ACL : structs . ACL {
Name : "User token" ,
Type : structs . ACLTokenTypeClient ,
} ,
}
var out string
err := msgpackrpc . CallWithCodec ( codec , "ACL.Apply" , & arg , & out )
require . True ( t , acl . IsErrPermissionDenied ( err ) , "Err %v is not acl.PermissionDenied" , err )
}
func TestACLEndpoint_Apply_DeleteAnon ( t * testing . T ) {
if testing . Short ( ) {
t . Skip ( "too slow for testing.Short" )
}
t . Parallel ( )
_ , srv , codec := testACLServerWithConfig ( t , nil , false )
waitForLeaderEstablishment ( t , srv )
arg := structs . ACLRequest {
Datacenter : "dc1" ,
Op : structs . ACLDelete ,
ACL : structs . ACL {
ID : anonymousToken ,
Name : "User token" ,
Type : structs . ACLTokenTypeClient ,
} ,
WriteRequest : structs . WriteRequest { Token : TestDefaultMasterToken } ,
}
var out string
err := msgpackrpc . CallWithCodec ( codec , "ACL.Apply" , & arg , & out )
testutil . RequireErrorContains ( t , err , "delete anonymous" )
}
func TestACLEndpoint_Apply_RootChange ( t * testing . T ) {
if testing . Short ( ) {
t . Skip ( "too slow for testing.Short" )
}
t . Parallel ( )
_ , srv , codec := testACLServerWithConfig ( t , nil , false )
waitForLeaderEstablishment ( t , srv )
arg := structs . ACLRequest {
Datacenter : "dc1" ,
Op : structs . ACLSet ,
ACL : structs . ACL {
ID : "manage" ,
Name : "User token" ,
Type : structs . ACLTokenTypeClient ,
} ,
WriteRequest : structs . WriteRequest { Token : TestDefaultMasterToken } ,
}
var out string
err := msgpackrpc . CallWithCodec ( codec , "ACL.Apply" , & arg , & out )
testutil . RequireErrorContains ( t , err , "root ACL" )
}
func TestACLEndpoint_GetPolicy ( t * testing . T ) {
if testing . Short ( ) {
t . Skip ( "too slow for testing.Short" )
}
t . Parallel ( )
_ , srv , codec := testACLServerWithConfig ( t , nil , false )
waitForLeaderEstablishment ( t , srv )
arg := structs . ACLRequest {
Datacenter : "dc1" ,
Op : structs . ACLSet ,
ACL : structs . ACL {
Name : "User token" ,
Type : structs . ACLTokenTypeClient ,
} ,
WriteRequest : structs . WriteRequest { Token : TestDefaultMasterToken } ,
}
var out string
err := msgpackrpc . CallWithCodec ( codec , "ACL.Apply" , & arg , & out )
require . NoError ( t , err )
getR := structs . ACLPolicyResolveLegacyRequest {
Datacenter : "dc1" ,
ACL : out ,
}
var acls structs . ACLPolicyResolveLegacyResponse
retry . Run ( t , func ( r * retry . R ) {
err := msgpackrpc . CallWithCodec ( codec , "ACL.GetPolicy" , & getR , & acls )
require . NoError ( r , err )
require . NotNil ( t , acls . Policy )
require . Equal ( t , 30 * time . Second , acls . TTL )
} )
// Do a conditional lookup with etag
getR . ETag = acls . ETag
var out2 structs . ACLPolicyResolveLegacyResponse
require . NoError ( t , msgpackrpc . CallWithCodec ( codec , "ACL.GetPolicy" , & getR , & out2 ) )
require . Nil ( t , out2 . Policy )
require . Equal ( t , 30 * time . Second , out2 . TTL )
}
func TestACLEndpoint_GetPolicy_Management ( t * testing . T ) {
if testing . Short ( ) {
t . Skip ( "too slow for testing.Short" )