-
Notifications
You must be signed in to change notification settings - Fork 0
/
identity_appliance_test.go
484 lines (416 loc) · 13.2 KB
/
identity_appliance_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
package cli
import (
"fmt"
"sort"
"strconv"
"strings"
api "github.com/atricore/josso-api-go"
)
func (s *AccTestSuite) TestAccCliIdentityAppliance_import() {
var t = s.T()
t.Log("Acceptance test Import : basic appliance")
a, err := s.ImportAppliance("./samples/testacc-01.idmn")
if err != nil {
t.Errorf("importing test appliance : %v", err)
return
}
t.Logf("Imported appliance %s [%d]", *a.Name, *a.Id)
s.client.DeleteAppliance(strconv.FormatInt(a.GetId(), 10))
if err != nil {
t.Errorf("importing test appliance w/deleting : %v", err)
return
}
}
func (s *AccTestSuite) TestAccCliIdentityAppliance_crud() {
var t = s.T()
s.accClearData()
// Test CRUD
crudName := "testacc-z"
var orig *api.IdentityApplianceDefinitionDTO
var created api.IdentityApplianceDefinitionDTO
orig = createTestIdentityApplianceDefinitionDTO(crudName)
// Create
created, err := s.client.CreateAppliance(*orig)
if err != nil {
t.Errorf("creating identity appliance : %v", err)
return
}
if err := IdApplianceValidateCreate(orig, &created); err != nil {
t.Errorf("creating identity appliance : %v", err)
return
}
// Retrieve
retrieved, err := s.client.GetAppliance(crudName)
if err != nil {
t.Errorf("retrieving identity appilance : %v", err)
return
}
if err := IdApplianceValidateUpdate(&created, &retrieved); err != nil {
t.Errorf("retrieving identity appliance : %v", err)
return
}
// Update
retrieved.Namespace = api.PtrString("com.atricore.ida.a.mod")
updated, err := s.client.UpdateAppliance(retrieved)
if err != nil {
t.Errorf("retrieving identity appilance : %v", err)
return
}
if err := IdApplianceValidateUpdate(&retrieved, &updated); err != nil {
t.Errorf("retrieving identity appliance : %v", err)
return
}
// Delete
removed, err := s.client.DeleteAppliance(strconv.FormatInt(*updated.Id, 10))
if err != nil {
t.Errorf("deleting identity appilance : %v", err)
return
}
if !removed {
t.Errorf("deleting identity appliance : not found %d", *updated.Id)
return
}
// Test empty list
listOfAll, err := getTestAppliances(s.client)
if err != nil {
t.Error(err)
return
}
if len(listOfAll) != 0 {
// The list should be emtpy
t.Errorf("Invalid number of elements found %d, expeted 0", len(listOfAll))
return
}
// List of created elements, order by Name, (these elements must have all the variables of the structure)
var listOfCreated [2]api.IdentityApplianceDefinitionDTO
element1 := createTestIdentityApplianceDefinitionDTO("testacc-1")
listOfCreated[0], _ = s.client.CreateAppliance(*element1)
element2 := createTestIdentityApplianceDefinitionDTO("testacc-2")
listOfCreated[1], _ = s.client.CreateAppliance(*element2)
// Get list from server
listOfRead, err := getTestAppliances(s.client)
if err != nil {
t.Error(err)
return
}
// The list should have 2 elemetns
if len(listOfRead) != 2 {
// The list should be emtpy
t.Errorf("Invalid number of elements found %d, expected 2", len(listOfAll))
return
}
// Order list of read by Name
sort.SliceStable(listOfRead,
func(i, j int) bool {
return strings.Compare(*listOfRead[i].Name, *listOfRead[j].Name) < 0
},
)
// Validate each element from the list of created with the list of read
for idx, r := range listOfCreated {
if err = IdApplianceValidateUpdate(&r, &listOfRead[idx]); err != nil {
t.Error(err)
return
}
}
}
func (s *AccTestSuite) TestAccCliIdentityAppliance_z010() {
var t = s.T()
t.Log("Acceptance test z010 : basic appliance")
a, err := s.ImportAppliance("./samples/testacc-01.idmn")
if err != nil {
t.Errorf("z010, importing appliance : %v ", err)
return
}
sp, err := s.client.GetExtSaml2Sp(*a.Name, "sp-1")
if err != nil {
t.Errorf("z010, getting sp : %v ", err)
return
}
if sp.GetName() != "sp-1" {
t.Errorf("z010, unexpected sp name %s", sp.GetName())
return
}
fcsBLen := len(sp.GetFederatedConnectionsB())
if fcsBLen != 1 {
t.Errorf("z010, unexpedted number of federated connections B, got %d", fcsBLen)
return
}
/*
for _, fcB := range sp.GetFederatedConnectionsB() {
t.Logf("Federated Connection %s", fcB.GetName())
idpC, err := fcB.GetIDPChannel()
if err != nil {
t.Errorf("%v", err)
}
spC, err := fcB.GetSPChannel()
if err != nil {
t.Errorf("%v", err)
}
t.Logf("%#v", fcB)
t.Logf("%#v", idpC)
t.Logf("%#v", spC)
}
*/
s.client.DeleteAppliance(strconv.FormatInt(a.GetId(), 10))
if err != nil {
t.Errorf("importing test appliance w/deleting : %v", err)
return
}
}
// Simple appliance test:
// - one idp
// - basic authn
// - identity vault
// - external saml2 sp
// - openid connect rp
func (s *AccTestSuite) TestAccCliIdentityAppliance_z030() {
var t = s.T()
t.Log("Acceptance test #030 : basic idp w/saml2 and oidc rp")
// 0. Create test appliance
template := createTestIdentityApplianceDefinitionDTO("testacc-s")
var err error
appliance, err := s.client.CreateAppliance(*template)
if err != nil {
t.Errorf("creating appliance: %v", err)
return
}
// 1. Create identity vault
origIdVauld := createTestEmbeddedIdentityVaultDTO("idv-1")
var createdIdVaul api.EmbeddedIdentityVaultDTO
createdIdVaul, err = s.client.CreateIdVault(appliance.GetName(), *origIdVauld)
if err != nil {
t.Errorf("create identity appliance: %v", err)
return
}
if err := IdVaultValidateCreate(origIdVauld, &createdIdVaul); err != nil {
t.Errorf("creating idVault : %v", err)
return
}
// 2. Create IdP using DB identity vault
var authns []api.AuthenticationMechanismDTO
authns = append(authns, createTestBasicAuthn())
idp, err := createTestIdentityProviderDTO("idp-1", authns)
if err != nil {
t.Errorf("Create identity appliance : %v", err)
return
}
*idp, err = s.client.CreateIdp(template.GetName(), *idp)
if err != nil {
t.Errorf("Create identity appliance : %v", err)
return
}
idp.AddIdentityLookup("id-lookup-1")
// 3. Create external SAML 2 sp, using test metadata and connect it to the IdP
origsaml2 := createTestExternalSaml2ServiceProviderDTO("sml2-sp")
var createdsaml2 api.ExternalSaml2ServiceProviderDTO
createdsaml2, err = s.client.CreateExtSaml2Sp(appliance.GetName(), *origsaml2)
if err != nil {
t.Errorf("create Saml2Sp: %v", err)
return
}
if err := ExternalSaml2SpValidateUpdate(origsaml2, &createdsaml2); err != nil {
t.Errorf("creating Saml2Sp : %v", err)
return
}
// 4. Create OidcRp
origOidcRp := createTestExternalOpenIDConnectRelayingPartyDTO("Oidc-Rp")
var createdOidcRp api.ExternalOpenIDConnectRelayingPartyDTO
createdOidcRp, err = s.client.CreateOidcRp(appliance.GetName(), *origOidcRp)
if err != nil {
t.Error(err)
return
}
if err := OidcRpValidateCreate(origOidcRp, &createdOidcRp); err != nil {
t.Errorf("creating OidcRp : %v", err)
return
}
}
// Simple appliance test:
// - one idp
// - basic authn
// - db identity source
// - external saml2 sp
// - partnerapp tomcat
func (s *AccTestSuite) TestAccCliIdentityAppliance_z040() {
var t = s.T()
t.Log("Acceptance test #040 : basic idp w/partnerapp and db")
// 0. Create test appliance
template := createTestIdentityApplianceDefinitionDTO("testacc-z040")
var err error
appliance, err := s.client.CreateAppliance(*template)
if err != nil {
t.Errorf("creating appliance: %v", err)
return
}
// 1. Create identity source
origIdsource := createTestDbIdentitySourceDTO("ids-1")
var createdIdVaul api.DbIdentitySourceDTO
createdIdVaul, err = s.client.CreateDbIdentitySourceDTO(appliance.GetName(), *origIdsource)
if err != nil {
t.Errorf("create identity appliance: %v", err)
return
}
if err := DbIdentitySourceValidateCreate(origIdsource, &createdIdVaul); err != nil {
t.Errorf("creating idsource : %v", err)
return
}
// 2. Create IdP using DB identity vault
var authns []api.AuthenticationMechanismDTO
authns = append(authns, createTestBasicAuthn())
idp, err := createTestIdentityProviderDTO("idp-1", authns)
if err != nil {
t.Errorf("Create identity appliance : %v", err)
return
}
*idp, err = s.client.CreateIdp(template.GetName(), *idp)
if err != nil {
t.Errorf("Create identity appliance : %v", err)
return
}
idp.AddIdentityLookup("id-lookup-1")
// 3. Create external SAML 2 sp, using test metadata and connect it to the IdP
origsaml2 := createTestExternalSaml2ServiceProviderDTO("sml2-sp")
var createdsaml2 api.ExternalSaml2ServiceProviderDTO
createdsaml2, err = s.client.CreateExtSaml2Sp(appliance.GetName(), *origsaml2)
if err != nil {
t.Errorf("create Saml2Sp: %v", err)
return
}
if err := ExternalSaml2SpValidateUpdate(origsaml2, &createdsaml2); err != nil {
t.Errorf("creating Saml2Sp : %v", err)
return
}
}
// ---------------------------------------------------------
func createTestIdentityApplianceDefinitionDTO(name string) *api.IdentityApplianceDefinitionDTO {
tData := api.NewIdentityApplianceDefinitionDTO()
var locat api.LocationDTO
locat.SetContext("IDBUS")
locat.SetHost("localhost")
locat.SetPort(8081)
locat.SetProtocol("http")
locat.SetUri(strings.ToUpper(name))
tData.SetLocation(locat)
var branding api.UserDashboardBrandingDTO
branding.SetName("josso25-branding")
tData.SetUserDashboardBranding(branding)
var scfg api.IdentityApplianceSecurityConfigDTO
scfg.SetEncryptSensitiveData(false)
//scfg.SetEncryption("AES128-CBC/SHA256")
//scfg.SetEncryptionConfig("")
scfg.SetEncryptionConfigFile(fmt.Sprintf("cfg-%s.properties", name))
scfg.SetEncryptionPassword(fmt.Sprintf("pwd%s", name))
scfg.SetExternalConfig(false)
// scfg.SetExternalConfigFile(fmt.Sprintf("sec-%s.properties", name))
// scfg.SetPasswordProperty("")
// scfg.SetSalt("")
// scfg.SetSaltProperty("")
// scfg.SetSaltValue("")
tData.SetSecurityConfig(scfg)
var es api.EntitySelectionStrategyDTO
es.SetName("requested-preferred-idp-selection")
tData.SetIdpSelector(es)
tData.SetDescription(fmt.Sprintf("Desc %s", name))
tData.SetDisplayName(fmt.Sprintf("DispName %s", name))
tData.SetName(name)
tData.SetNamespace(fmt.Sprintf("com.atricore.idbus.ida.%s", sanitizeName(name)))
// orig.SetRequiredBundles() //
return tData
}
// -------------------------------------------------
// Fields to validate after appliance creation
func ApplianceFieldTestCreate(
e *api.IdentityApplianceDefinitionDTO,
r *api.IdentityApplianceDefinitionDTO) []FiledTestStruct {
return []FiledTestStruct{
// {
// name: "userdashboardbranding",
// cmp: func() bool { return UserBrandingPtrEquals(e.UserDashboardBranding, r.UserDashboardBranding) },
// expected: StrDeref(e.UserDashboardBranding),
// received: StrDeref(r.UserDashboardBranding),
// },
// {
// name: "securityconfig",
// cmp: func() bool { return IDASCPtrEquals(e.SecurityConfig, r.SecurityConfig) },
// expected: StrDeref(e.SecurityConfig),
// received: StrDeref(r.SecurityConfig),
// },
// {
// name: "keystore",
// cmp: func() bool { return KeystorePtrEquals(e.Keystore, r.Keystore) },
// expected: StrDeref(e.Keystore),
// received: StrDeref(r.Keystore),
// },
// {
// name: "idpselector",
// cmp: func() bool { return EntitySelectionPtrEquals(e.IdpSelector, r.IdpSelector) },
// expected: StrDeref(e.IdpSelector),
// received: StrDeref(r.IdpSelector),
// },
{
name: "description",
cmp: func() bool { return StrPtrEquals(e.Description, r.Description) },
expected: StrDeref(e.Description),
received: StrDeref(r.Description),
},
{
name: "display_name",
cmp: func() bool { return StrPtrEquals(e.DisplayName, r.DisplayName) },
expected: StrDeref(e.DisplayName),
received: StrDeref(r.DisplayName),
},
{
name: "name",
cmp: func() bool { return StrPtrEquals(e.Name, r.Name) },
expected: StrDeref(e.Name),
received: StrDeref(r.Name),
},
{
name: "name_space",
cmp: func() bool { return StrPtrEquals(e.Namespace, r.Namespace) },
expected: StrDeref(e.Namespace),
received: StrDeref(r.Namespace),
},
}
}
// Fields to validate after appliance update
func ApplianceFieldTestUpdate(
e *api.IdentityApplianceDefinitionDTO,
r *api.IdentityApplianceDefinitionDTO) []FiledTestStruct {
t := []FiledTestStruct{
{
name: "location",
cmp: func() bool { return LocationPtrEquals(e.Location, r.Location) },
expected: LocationToStr(e.Location),
received: LocationToStr(r.Location),
},
}
return append(t, ApplianceFieldTestCreate(e, r)...)
}
// Compares the expected appliance with the received one.
func IdApplianceValidateCreate(
e *api.IdentityApplianceDefinitionDTO,
r *api.IdentityApplianceDefinitionDTO) error {
return ValidateFields(ApplianceFieldTestCreate(e, r))
}
// Compares the expected appliance with the received one.
func IdApplianceValidateUpdate(
e *api.IdentityApplianceDefinitionDTO,
r *api.IdentityApplianceDefinitionDTO) error {
return ValidateFields(ApplianceFieldTestUpdate(e, r))
}
// This gets all applinaces from the server that are used as acceptance test (name starts with testacc-)
func getTestAppliances(c *IdbusApiClient) ([]api.IdentityApplianceDefinitionDTO, error) {
// Get list from server
var r []api.IdentityApplianceDefinitionDTO
listOfRead, err := c.GetAppliances()
if err != nil {
return r, err
}
for _, a := range listOfRead {
if strings.HasPrefix(a.GetName(), "testacc-") {
r = append(r, a)
}
}
return r, nil
}