Skip to content

Commit 8626b94

Browse files
Birdrockandrewedstrom
authored andcommitted
create-user doesn't require givenName/familyName
- Previously was required in CLI, but optional for UAA API. [#168790909] Signed-off-by: Andrew Edstrom <aedstrom@pivotal.io>
1 parent 79fbfb3 commit 8626b94

3 files changed

Lines changed: 193 additions & 81 deletions

File tree

cmd/create_user.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,6 @@ func CreateUserValidation(cfg config.Config, args []string, familyName, givenNam
6363
if len(args) == 0 {
6464
return errors.New("The positional argument USERNAME must be specified.")
6565
}
66-
if familyName == "" {
67-
return cli.MissingArgumentError("familyName")
68-
}
69-
if givenName == "" {
70-
return cli.MissingArgumentError("givenName")
71-
}
7266
if len(emails) == 0 {
7367
return cli.MissingArgumentError("email")
7468
}

cmd/create_user_test.go

Lines changed: 142 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -45,23 +45,6 @@ var _ = Describe("CreateUser", func() {
4545
Expect(session.Err).To(Say("The positional argument USERNAME must be specified."))
4646
})
4747

48-
It("requires a family name (last name)", func() {
49-
session := runCommand("create-user", "woodstock")
50-
51-
Eventually(session).Should(Exit(1))
52-
Expect(session.Err).To(Say("Missing argument `familyName` must be specified."))
53-
})
54-
55-
It("requires a given name (first name)", func() {
56-
session := runCommand("create-user",
57-
"woodstock",
58-
"--familyName", "Bird",
59-
)
60-
61-
Eventually(session).Should(Exit(1))
62-
Expect(session.Err).To(Say("Missing argument `givenName` must be specified."))
63-
})
64-
6548
It("requires an email address", func() {
6649
session := runCommand("create-user",
6750
"woodstock",
@@ -73,17 +56,17 @@ var _ = Describe("CreateUser", func() {
7356
Expect(session.Err).To(Say("Missing argument `email` must be specified."))
7457
})
7558
})
76-
7759
Describe("CreateUserCmd", func() {
78-
It("performs POST with user data and bearer token", func() {
79-
server.RouteToHandler("POST", "/Users", CombineHandlers(
80-
RespondWith(http.StatusOK, fixtures.MarcusUserResponse),
81-
VerifyRequest("POST", "/Users"),
82-
VerifyHeaderKV("Authorization", "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ"),
83-
VerifyHeaderKV("Accept", "application/json"),
84-
VerifyHeaderKV("Content-Type", "application/json"),
85-
VerifyHeaderKV("X-Identity-Zone-Id", "twilight-zone"),
86-
VerifyJSON(`
60+
Describe("With name", func() {
61+
It("performs POST with user data and bearer token", func() {
62+
server.RouteToHandler("POST", "/Users", CombineHandlers(
63+
RespondWith(http.StatusOK, fixtures.MarcusUserResponse),
64+
VerifyRequest("POST", "/Users"),
65+
VerifyHeaderKV("Authorization", "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ"),
66+
VerifyHeaderKV("Accept", "application/json"),
67+
VerifyHeaderKV("Content-Type", "application/json"),
68+
VerifyHeaderKV("X-Identity-Zone-Id", "twilight-zone"),
69+
VerifyJSON(`
8770
{
8871
"userName": "marcus",
8972
"password": "secret",
@@ -107,57 +90,141 @@ var _ = Describe("CreateUser", func() {
10790
}]
10891
}
10992
`),
110-
))
111-
112-
session := runCommand("create-user", "marcus",
113-
"--givenName", "Marcus",
114-
"--familyName", "Aurelius",
115-
"--email", "marcus@philosophy.com",
116-
"--email", "marcusA@gmail.com",
117-
"--phone", "555-5555",
118-
"--phone", "666-6666",
119-
"--password", "secret",
120-
"--origin", "uaa",
121-
"--zone", "twilight-zone",
122-
)
123-
124-
Expect(server.ReceivedRequests()).To(HaveLen(1))
125-
Expect(session).To(Exit(0))
93+
))
94+
95+
session := runCommand("create-user", "marcus",
96+
"--givenName", "Marcus",
97+
"--familyName", "Aurelius",
98+
"--email", "marcus@philosophy.com",
99+
"--email", "marcusA@gmail.com",
100+
"--phone", "555-5555",
101+
"--phone", "666-6666",
102+
"--password", "secret",
103+
"--origin", "uaa",
104+
"--zone", "twilight-zone",
105+
)
106+
107+
Expect(server.ReceivedRequests()).To(HaveLen(1))
108+
Expect(session).To(Exit(0))
109+
})
110+
111+
It("prints the created user json", func() {
112+
server.RouteToHandler("POST", "/Users", CombineHandlers(
113+
RespondWith(http.StatusOK, fixtures.MarcusUserResponse),
114+
VerifyRequest("POST", "/Users"),
115+
))
116+
117+
session := runCommand("create-user", "marcus",
118+
"--givenName", "Marcus",
119+
"--familyName", "Aurelius",
120+
"--email", "marcus@philosophy.com",
121+
"--email", "marcusA@gmail.com",
122+
)
123+
124+
Expect(server.ReceivedRequests()).To(HaveLen(1))
125+
Expect(session).To(Exit(0))
126+
Expect(session.Out.Contents()).To(MatchJSON(fixtures.MarcusUserResponse))
127+
})
128+
129+
It("displays an error if there is a problem during create", func() {
130+
server.RouteToHandler("POST", "/Users", CombineHandlers(
131+
RespondWith(http.StatusBadRequest, ""),
132+
VerifyRequest("POST", "/Users"),
133+
))
134+
135+
session := runCommand("create-user", "marcus",
136+
"--givenName", "Marcus",
137+
"--familyName", "Aurelius",
138+
"--email", "marcus@philosophy.com",
139+
"--email", "marcusA@gmail.com",
140+
)
141+
142+
Expect(server.ReceivedRequests()).To(HaveLen(1))
143+
Expect(session).To(Exit(1))
144+
})
126145
})
127146

128-
It("prints the created user json", func() {
129-
server.RouteToHandler("POST", "/Users", CombineHandlers(
130-
RespondWith(http.StatusOK, fixtures.MarcusUserResponse),
131-
VerifyRequest("POST", "/Users"),
132-
))
133-
134-
session := runCommand("create-user", "marcus",
135-
"--givenName", "Marcus",
136-
"--familyName", "Aurelius",
137-
"--email", "marcus@philosophy.com",
138-
"--email", "marcusA@gmail.com",
139-
)
140-
141-
Expect(server.ReceivedRequests()).To(HaveLen(1))
142-
Expect(session).To(Exit(0))
143-
Expect(session.Out.Contents()).To(MatchJSON(fixtures.MarcusUserResponse))
147+
Describe("Without name", func() {
148+
It("performs POST with user data and bearer token", func() {
149+
server.RouteToHandler("POST", "/Users", CombineHandlers(
150+
RespondWith(http.StatusOK, fixtures.MarcusUserResponse),
151+
VerifyRequest("POST", "/Users"),
152+
VerifyHeaderKV("Authorization", "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ"),
153+
VerifyHeaderKV("Accept", "application/json"),
154+
VerifyHeaderKV("Content-Type", "application/json"),
155+
VerifyHeaderKV("X-Identity-Zone-Id", "twilight-zone"),
156+
VerifyJSON(`
157+
{
158+
"userName": "marcus",
159+
"password": "secret",
160+
"origin": "uaa",
161+
"name" : {},
162+
"emails": [
163+
{
164+
"value": "marcus@philosophy.com",
165+
"primary": true
166+
},
167+
{
168+
"value": "marcusA@gmail.com",
169+
"primary": false
170+
}
171+
],
172+
"phoneNumbers": [{
173+
"value": "555-5555"
174+
},
175+
{
176+
"value": "666-6666"
177+
}]
178+
}
179+
`),
180+
))
181+
182+
session := runCommand("create-user", "marcus",
183+
"--email", "marcus@philosophy.com",
184+
"--email", "marcusA@gmail.com",
185+
"--phone", "555-5555",
186+
"--phone", "666-6666",
187+
"--password", "secret",
188+
"--origin", "uaa",
189+
"--zone", "twilight-zone",
190+
)
191+
192+
Expect(server.ReceivedRequests()).To(HaveLen(1))
193+
Expect(session).To(Exit(0))
194+
})
195+
196+
It("prints the created user json", func() {
197+
server.RouteToHandler("POST", "/Users", CombineHandlers(
198+
RespondWith(http.StatusOK, fixtures.AnonyMarcusUserResponse),
199+
VerifyRequest("POST", "/Users"),
200+
))
201+
202+
session := runCommand("create-user", "marcus",
203+
"--email", "marcus@philosophy.com",
204+
"--email", "marcusA@gmail.com",
205+
)
206+
207+
Expect(server.ReceivedRequests()).To(HaveLen(1))
208+
Expect(session).To(Exit(0))
209+
Expect(session.Out.Contents()).To(MatchJSON(fixtures.AnonyMarcusUserResponse))
210+
})
211+
212+
It("displays an error if there is a problem during create", func() {
213+
server.RouteToHandler("POST", "/Users", CombineHandlers(
214+
RespondWith(http.StatusBadRequest, ""),
215+
VerifyRequest("POST", "/Users"),
216+
))
217+
218+
session := runCommand("create-user", "marcus",
219+
"--email", "marcus@philosophy.com",
220+
"--email", "marcusA@gmail.com",
221+
)
222+
223+
Expect(server.ReceivedRequests()).To(HaveLen(1))
224+
Expect(session).To(Exit(1))
225+
})
144226
})
145227

146-
It("displays an error if there is a problem during create", func() {
147-
server.RouteToHandler("POST", "/Users", CombineHandlers(
148-
RespondWith(http.StatusBadRequest, ""),
149-
VerifyRequest("POST", "/Users"),
150-
))
151-
152-
session := runCommand("create-user", "marcus",
153-
"--givenName", "Marcus",
154-
"--familyName", "Aurelius",
155-
"--email", "marcus@philosophy.com",
156-
"--email", "marcusA@gmail.com",
157-
)
158-
159-
Expect(server.ReceivedRequests()).To(HaveLen(1))
160-
Expect(session).To(Exit(1))
161-
})
162228
})
229+
163230
})

fixtures/users.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,57 @@ const MarcusUserResponse = `{
5959
"schemas" : [ "urn:scim:schemas:core:1.0" ]
6060
}`
6161

62+
const AnonyMarcusUserResponse = `{
63+
"id" : "fb5f32e1-5cb3-49e6-93df-6df9c8c8bd70",
64+
"externalId" : "marcus-user",
65+
"meta" : {
66+
"version" : 1,
67+
"created" : "2017-01-15T16:54:15.677Z",
68+
"lastModified" : "2017-08-15T16:54:15.677Z"
69+
},
70+
"userName" : "marcus@stoicism.com",
71+
"name" : {},
72+
"emails" : [ {
73+
"value" : "marcus@stoicism.com",
74+
"primary" : false
75+
} ],
76+
"groups" : [ {
77+
"value" : "ac2ab20e-0a2d-4b68-82e4-817ee6b258b4",
78+
"display" : "philosophy.read",
79+
"type" : "DIRECT"
80+
}, {
81+
"value" : "110b2434-4a30-439b-b5fc-f4cf47fc04f0",
82+
"display" : "philosophy.write",
83+
"type" : "DIRECT"
84+
}],
85+
"approvals" : [ {
86+
"userId" : "fb5f32e1-5cb3-49e6-93df-6df9c8c8bd70",
87+
"clientId" : "shinyclient",
88+
"scope" : "philosophy.read",
89+
"status" : "APPROVED",
90+
"lastUpdatedAt" : "2017-08-15T16:54:15.765Z",
91+
"expiresAt" : "2017-08-15T16:54:25.765Z"
92+
}, {
93+
"userId" : "fb5f32e1-5cb3-49e6-93df-6df9c8c8bd70",
94+
"clientId" : "identity",
95+
"scope" : "uaa.user",
96+
"status" : "APPROVED",
97+
"lastUpdatedAt" : "2017-08-15T16:54:45.767Z",
98+
"expiresAt" : "2017-08-15T16:54:45.767Z"
99+
} ],
100+
"phoneNumbers" : [ {
101+
"value" : "5555555555"
102+
} ],
103+
"active" : true,
104+
"verified" : true,
105+
"origin" : "uaa",
106+
"zoneId" : "uaa",
107+
"passwordLastModified" : "2017-08-15T16:54:15.000Z",
108+
"previousLogonTime" : 1502816055768,
109+
"lastLogonTime" : 1502816055768,
110+
"schemas" : [ "urn:scim:schemas:core:1.0" ]
111+
}`
112+
62113
const DrSeussUserResponse = `{
63114
"id" : "fb5f32e1-5cb3-49e6-93df-6df9c8c8bd70",
64115
"externalId" : "seuss-user",

0 commit comments

Comments
 (0)