@@ -15,26 +15,34 @@ func TestCreateUserSelfRegistration(t *testing.T) {
15
15
teardown := setup (t )
16
16
defer teardown ()
17
17
18
+ newUserUUID := "867128a6-0e02-431c-ba1e-9e764436dae4"
19
+ loginID := "loafoe"
20
+
21
+ firstName := "La"
22
+ lastName := "Foe"
23
+
18
24
muxIDM .HandleFunc ("/authorize/identity/User" , func (w http.ResponseWriter , r * http.Request ) {
19
- if r .Method != "POST" {
20
- t .Errorf ("Expected ‘POST’ request, got ‘%s’" , r .Method )
21
- }
22
25
if auth := r .Header .Get ("Authorization" ); auth != "" {
23
26
t .Errorf ("No Authorization header expected, Got: %s" , auth )
27
+ w .WriteHeader (http .StatusUnauthorized )
28
+ return
24
29
}
25
- body , _ := ioutil .ReadAll (r .Body )
26
- j , _ := gabs .ParseJSON (body )
27
- ageValidated , ok := j .Path ("isAgeValidated" ).Data ().(string )
28
- if ! ok {
29
- t .Errorf ("Missing isAgeValidated field" )
30
- }
31
- if ageValidated != "true" {
32
- t .Errorf ("ageValidated should be true" )
33
- }
34
-
35
- w .Header ().Set ("Content-Type" , "application/json;charset=UTF-8" )
36
- w .WriteHeader (http .StatusCreated )
37
- _ , _ = io .WriteString (w , `{
30
+ switch r .Method {
31
+ case "POST" :
32
+ body , _ := ioutil .ReadAll (r .Body )
33
+ j , _ := gabs .ParseJSON (body )
34
+ ageValidated , ok := j .Path ("isAgeValidated" ).Data ().(string )
35
+ if ! ok {
36
+ t .Errorf ("Missing isAgeValidated field" )
37
+ }
38
+ if ageValidated != "true" {
39
+ t .Errorf ("ageValidated should be true" )
40
+ }
41
+
42
+ w .Header ().Set ("Content-Type" , "application/json;charset=UTF-8" )
43
+ w .Header ().Set ("Location" , "/authorize/identity/User/" + newUserUUID )
44
+ w .WriteHeader (http .StatusCreated )
45
+ _ , _ = io .WriteString (w , `{
38
46
"resourceType": "OperationOutcome",
39
47
"issue": [
40
48
{
@@ -46,13 +54,72 @@ func TestCreateUserSelfRegistration(t *testing.T) {
46
54
}
47
55
]
48
56
}` )
57
+ case "GET" :
58
+ w .WriteHeader (http .StatusOK )
59
+ _ , _ = io .WriteString (w , `{
60
+ "total": 1,
61
+ "entry": [
62
+ {
63
+ "preferredLanguage": "en-US",
64
+ "loginId": "` + loginID + `",
65
+ "emailAddress": "` + email + `",
66
+ "id": "` + newUserUUID + `",
67
+ "managingOrganization": "c29cdb88-7cda-4fc1-af8b-ee5947659958",
68
+ "name": {
69
+ "given": "` + firstName + `",
70
+ "family": "` + lastName + `"
71
+ },
72
+ "memberships": [
73
+ {
74
+ "organizationId": "c29cdb88-7cda-4fc1-af8b-ee5947659958",
75
+ "organizationName": "Pawnee",
76
+ "roles": [
77
+ "ANALYZE",
78
+ "S3CREDSADMINROLE",
79
+ "ADMIN"
80
+ ],
81
+ "groups": [
82
+ "S3CredsAdminGroup",
83
+ "AdminGroup"
84
+ ]
85
+ },
86
+ {
87
+ "organizationId": "d4be75cc-e81b-4d7d-b034-baf6f3f10792",
88
+ "organizationName": "Eagleton",
89
+ "roles": [
90
+ "LOGUSER"
91
+ ],
92
+ "groups": [
93
+ "LogUserGroup"
94
+ ]
95
+ }
96
+ ],
97
+ "passwordStatus": {
98
+ "passwordExpiresOn": "2022-02-04T10:07:55Z",
99
+ "passwordChangedOn": "2020-02-15T10:07:55Z"
100
+ },
101
+ "accountStatus": {
102
+ "mfaStatus": "NOTREQUIRED",
103
+ "lastLoginTime": "2020-05-09T12:27:41Z",
104
+ "emailVerified": true,
105
+ "numberOfInvalidAttempt": 0,
106
+ "disabled": false
107
+ },
108
+ "consentedApps": [
109
+ "default default default"
110
+ ]
111
+ }
112
+ ]
113
+ }` )
114
+ }
115
+
49
116
})
50
117
person := Person {
51
118
ResourceType : "Person" ,
52
- LoginID : "loafoe" ,
119
+ LoginID : loginID ,
53
120
Name : Name {
54
- Family : "Foe" ,
55
- Given : "La" ,
121
+ Family : lastName ,
122
+ Given : firstName ,
56
123
},
57
124
Telecom : []TelecomEntry {
58
125
{
@@ -66,13 +133,17 @@ func TestCreateUserSelfRegistration(t *testing.T) {
66
133
},
67
134
IsAgeValidated : "true" ,
68
135
}
69
- ok , resp , err := client .Users .CreateUser (person )
136
+ user , resp , err := client .Users .CreateUser (person )
70
137
if ! assert .NotNil (t , resp ) {
71
138
return
72
139
}
140
+ assert .Equal (t , http .StatusOK , resp .StatusCode )
73
141
assert .Nil (t , err )
74
- assert .True (t , ok )
75
- assert .Equal (t , http .StatusCreated , resp .StatusCode )
142
+ if ! assert .NotNil (t , user ) {
143
+ return
144
+ }
145
+ assert .Equal (t , newUserUUID , user .ID )
146
+ assert .Equal (t , loginID , user .LoginID )
76
147
}
77
148
78
149
func TestDeleteUser (t * testing.T ) {
0 commit comments