@@ -20,20 +20,29 @@ func TestBackend_basic(t *testing.T) {
2020 t .Fatal (err )
2121 }
2222
23- roleConfig := roleConfig {
24- Connection : "testconn" ,
25- Roles : []string {"admin" },
26- UserPrefix : defaultUserPrefix ,
23+ schemes := []string {
24+ userIDSchemeUUID4_v0_5_0 ,
25+ userIDSchemeUUID4 ,
26+ userIDSchemeBase58_64 ,
27+ userIDSchemeBase58_128 ,
2728 }
29+ for _ , scheme := range schemes {
30+ roleConfig := roleConfig {
31+ Connection : "testconn" ,
32+ Roles : []string {"admin" },
33+ UserPrefix : defaultUserPrefix ,
34+ UserIDScheme : scheme ,
35+ }
2836
29- logicaltest .Test (t , logicaltest.TestCase {
30- LogicalBackend : b ,
31- Steps : []logicaltest.TestStep {
32- testAccStepConfig (t ),
33- testAccStepRole (t , "test" , roleConfig ),
34- testAccStepCredsRead (t , "test" ),
35- },
36- })
37+ logicaltest .Test (t , logicaltest.TestCase {
38+ LogicalBackend : b ,
39+ Steps : []logicaltest.TestStep {
40+ testAccStepConfig (t ),
41+ testAccStepRole (t , "test" , roleConfig ),
42+ testAccStepCredsRead (t , "test" ),
43+ },
44+ })
45+ }
3746}
3847
3948func TestBackend_RotateRoot (t * testing.T ) {
@@ -92,6 +101,7 @@ func TestBackend_RoleCRUD(t *testing.T) {
92101 AllowedServerRoles : []string {"*" },
93102 PasswordSpec : DefaultPasswordSpec (),
94103 UserPrefix : "my-custom-prefix" ,
104+ UserIDScheme : userIDSchemeUUID4 ,
95105 }
96106
97107 logicaltest .Test (t , logicaltest.TestCase {
@@ -105,17 +115,23 @@ func TestBackend_RoleCRUD(t *testing.T) {
105115 testAccStepRoleDelete (t , "test" ),
106116 },
107117 })
108- emptyUserPrefixConfig := roleConfig {
109- Connection : "testconn" ,
110- Roles : []string {"admin" },
111- UserPrefix : "" ,
112- }
118+ emptyUserPrefixConfig := testRoleConfig
119+ emptyUserPrefixConfig .UserPrefix = ""
113120 logicaltest .Test (t , logicaltest.TestCase {
114121 LogicalBackend : b ,
115122 Steps : []logicaltest.TestStep {
116123 testEmptyUserPrefix (t , "test" , emptyUserPrefixConfig ),
117124 },
118125 })
126+
127+ userIDSchemeConfig := testRoleConfig
128+ userIDSchemeConfig .UserIDScheme = "-invalid-"
129+ logicaltest .Test (t , logicaltest.TestCase {
130+ LogicalBackend : b ,
131+ Steps : []logicaltest.TestStep {
132+ testUserIDScheme (t , "test" , "-invalid-" , userIDSchemeConfig ),
133+ },
134+ })
119135}
120136
121137// Test steps
@@ -219,6 +235,22 @@ func testEmptyUserPrefix(t *testing.T, role string, config roleConfig) logicalte
219235 }
220236}
221237
238+ func testUserIDScheme (t * testing.T , role , idScheme string , config roleConfig ) logicaltest.TestStep {
239+ return logicaltest.TestStep {
240+ Operation : logical .CreateOperation ,
241+ Path : rolesPrefix + role ,
242+ Data : config .toResponseData (),
243+ ErrorOk : true ,
244+ Check : func (resp * logical.Response ) error {
245+ if resp == nil {
246+ return fmt .Errorf ("response is nil" )
247+ }
248+ assert .Error (t , resp .Error (), fmt .Sprintf ("invalid user_id_scheme: %q" , idScheme ))
249+ return nil
250+ },
251+ }
252+ }
253+
222254func testAccStepCredsRead (t * testing.T , role string ) logicaltest.TestStep {
223255 return logicaltest.TestStep {
224256 Operation : logical .ReadOperation ,
@@ -235,8 +267,11 @@ func testAccStepCredsRead(t *testing.T, role string) logicaltest.TestStep {
235267 if err := mapstructure .Decode (resp .Data , & d ); err != nil {
236268 return err
237269 }
238- t .Logf ("[WARN] Generated credentials: %+v" , d )
239- // XXXX check that generated user can login
270+ // check that generated user can login
271+ conn := splunk .NewTestSplunkClient (d .URL , d .Username , d .Password )
272+ _ , _ , err := conn .Introspection .ServerInfo ()
273+ assert .NilError (t , err )
274+
240275 // XXXX check that generated user is deleted if lease expires
241276 return nil
242277 },
0 commit comments