Skip to content

Commit

Permalink
create-user doesn't require givenName/familyName
Browse files Browse the repository at this point in the history
- Previously was required in CLI, but optional for UAA API.

[#168790909]

Signed-off-by: Andrew Edstrom <aedstrom@pivotal.io>
  • Loading branch information
Birdrock authored and andrewedstrom committed Oct 30, 2019
1 parent 79fbfb3 commit 8626b94
Show file tree
Hide file tree
Showing 3 changed files with 193 additions and 81 deletions.
6 changes: 0 additions & 6 deletions cmd/create_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,6 @@ func CreateUserValidation(cfg config.Config, args []string, familyName, givenNam
if len(args) == 0 {
return errors.New("The positional argument USERNAME must be specified.")
}
if familyName == "" {
return cli.MissingArgumentError("familyName")
}
if givenName == "" {
return cli.MissingArgumentError("givenName")
}
if len(emails) == 0 {
return cli.MissingArgumentError("email")
}
Expand Down
217 changes: 142 additions & 75 deletions cmd/create_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,6 @@ var _ = Describe("CreateUser", func() {
Expect(session.Err).To(Say("The positional argument USERNAME must be specified."))
})

It("requires a family name (last name)", func() {
session := runCommand("create-user", "woodstock")

Eventually(session).Should(Exit(1))
Expect(session.Err).To(Say("Missing argument `familyName` must be specified."))
})

It("requires a given name (first name)", func() {
session := runCommand("create-user",
"woodstock",
"--familyName", "Bird",
)

Eventually(session).Should(Exit(1))
Expect(session.Err).To(Say("Missing argument `givenName` must be specified."))
})

It("requires an email address", func() {
session := runCommand("create-user",
"woodstock",
Expand All @@ -73,17 +56,17 @@ var _ = Describe("CreateUser", func() {
Expect(session.Err).To(Say("Missing argument `email` must be specified."))
})
})

Describe("CreateUserCmd", func() {
It("performs POST with user data and bearer token", func() {
server.RouteToHandler("POST", "/Users", CombineHandlers(
RespondWith(http.StatusOK, fixtures.MarcusUserResponse),
VerifyRequest("POST", "/Users"),
VerifyHeaderKV("Authorization", "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ"),
VerifyHeaderKV("Accept", "application/json"),
VerifyHeaderKV("Content-Type", "application/json"),
VerifyHeaderKV("X-Identity-Zone-Id", "twilight-zone"),
VerifyJSON(`
Describe("With name", func() {
It("performs POST with user data and bearer token", func() {
server.RouteToHandler("POST", "/Users", CombineHandlers(
RespondWith(http.StatusOK, fixtures.MarcusUserResponse),
VerifyRequest("POST", "/Users"),
VerifyHeaderKV("Authorization", "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ"),
VerifyHeaderKV("Accept", "application/json"),
VerifyHeaderKV("Content-Type", "application/json"),
VerifyHeaderKV("X-Identity-Zone-Id", "twilight-zone"),
VerifyJSON(`
{
"userName": "marcus",
"password": "secret",
Expand All @@ -107,57 +90,141 @@ var _ = Describe("CreateUser", func() {
}]
}
`),
))

session := runCommand("create-user", "marcus",
"--givenName", "Marcus",
"--familyName", "Aurelius",
"--email", "marcus@philosophy.com",
"--email", "marcusA@gmail.com",
"--phone", "555-5555",
"--phone", "666-6666",
"--password", "secret",
"--origin", "uaa",
"--zone", "twilight-zone",
)

Expect(server.ReceivedRequests()).To(HaveLen(1))
Expect(session).To(Exit(0))
))

session := runCommand("create-user", "marcus",
"--givenName", "Marcus",
"--familyName", "Aurelius",
"--email", "marcus@philosophy.com",
"--email", "marcusA@gmail.com",
"--phone", "555-5555",
"--phone", "666-6666",
"--password", "secret",
"--origin", "uaa",
"--zone", "twilight-zone",
)

Expect(server.ReceivedRequests()).To(HaveLen(1))
Expect(session).To(Exit(0))
})

It("prints the created user json", func() {
server.RouteToHandler("POST", "/Users", CombineHandlers(
RespondWith(http.StatusOK, fixtures.MarcusUserResponse),
VerifyRequest("POST", "/Users"),
))

session := runCommand("create-user", "marcus",
"--givenName", "Marcus",
"--familyName", "Aurelius",
"--email", "marcus@philosophy.com",
"--email", "marcusA@gmail.com",
)

Expect(server.ReceivedRequests()).To(HaveLen(1))
Expect(session).To(Exit(0))
Expect(session.Out.Contents()).To(MatchJSON(fixtures.MarcusUserResponse))
})

It("displays an error if there is a problem during create", func() {
server.RouteToHandler("POST", "/Users", CombineHandlers(
RespondWith(http.StatusBadRequest, ""),
VerifyRequest("POST", "/Users"),
))

session := runCommand("create-user", "marcus",
"--givenName", "Marcus",
"--familyName", "Aurelius",
"--email", "marcus@philosophy.com",
"--email", "marcusA@gmail.com",
)

Expect(server.ReceivedRequests()).To(HaveLen(1))
Expect(session).To(Exit(1))
})
})

It("prints the created user json", func() {
server.RouteToHandler("POST", "/Users", CombineHandlers(
RespondWith(http.StatusOK, fixtures.MarcusUserResponse),
VerifyRequest("POST", "/Users"),
))

session := runCommand("create-user", "marcus",
"--givenName", "Marcus",
"--familyName", "Aurelius",
"--email", "marcus@philosophy.com",
"--email", "marcusA@gmail.com",
)

Expect(server.ReceivedRequests()).To(HaveLen(1))
Expect(session).To(Exit(0))
Expect(session.Out.Contents()).To(MatchJSON(fixtures.MarcusUserResponse))
Describe("Without name", func() {
It("performs POST with user data and bearer token", func() {
server.RouteToHandler("POST", "/Users", CombineHandlers(
RespondWith(http.StatusOK, fixtures.MarcusUserResponse),
VerifyRequest("POST", "/Users"),
VerifyHeaderKV("Authorization", "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ"),
VerifyHeaderKV("Accept", "application/json"),
VerifyHeaderKV("Content-Type", "application/json"),
VerifyHeaderKV("X-Identity-Zone-Id", "twilight-zone"),
VerifyJSON(`
{
"userName": "marcus",
"password": "secret",
"origin": "uaa",
"name" : {},
"emails": [
{
"value": "marcus@philosophy.com",
"primary": true
},
{
"value": "marcusA@gmail.com",
"primary": false
}
],
"phoneNumbers": [{
"value": "555-5555"
},
{
"value": "666-6666"
}]
}
`),
))

session := runCommand("create-user", "marcus",
"--email", "marcus@philosophy.com",
"--email", "marcusA@gmail.com",
"--phone", "555-5555",
"--phone", "666-6666",
"--password", "secret",
"--origin", "uaa",
"--zone", "twilight-zone",
)

Expect(server.ReceivedRequests()).To(HaveLen(1))
Expect(session).To(Exit(0))
})

It("prints the created user json", func() {
server.RouteToHandler("POST", "/Users", CombineHandlers(
RespondWith(http.StatusOK, fixtures.AnonyMarcusUserResponse),
VerifyRequest("POST", "/Users"),
))

session := runCommand("create-user", "marcus",
"--email", "marcus@philosophy.com",
"--email", "marcusA@gmail.com",
)

Expect(server.ReceivedRequests()).To(HaveLen(1))
Expect(session).To(Exit(0))
Expect(session.Out.Contents()).To(MatchJSON(fixtures.AnonyMarcusUserResponse))
})

It("displays an error if there is a problem during create", func() {
server.RouteToHandler("POST", "/Users", CombineHandlers(
RespondWith(http.StatusBadRequest, ""),
VerifyRequest("POST", "/Users"),
))

session := runCommand("create-user", "marcus",
"--email", "marcus@philosophy.com",
"--email", "marcusA@gmail.com",
)

Expect(server.ReceivedRequests()).To(HaveLen(1))
Expect(session).To(Exit(1))
})
})

It("displays an error if there is a problem during create", func() {
server.RouteToHandler("POST", "/Users", CombineHandlers(
RespondWith(http.StatusBadRequest, ""),
VerifyRequest("POST", "/Users"),
))

session := runCommand("create-user", "marcus",
"--givenName", "Marcus",
"--familyName", "Aurelius",
"--email", "marcus@philosophy.com",
"--email", "marcusA@gmail.com",
)

Expect(server.ReceivedRequests()).To(HaveLen(1))
Expect(session).To(Exit(1))
})
})

})
51 changes: 51 additions & 0 deletions fixtures/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,57 @@ const MarcusUserResponse = `{
"schemas" : [ "urn:scim:schemas:core:1.0" ]
}`

const AnonyMarcusUserResponse = `{
"id" : "fb5f32e1-5cb3-49e6-93df-6df9c8c8bd70",
"externalId" : "marcus-user",
"meta" : {
"version" : 1,
"created" : "2017-01-15T16:54:15.677Z",
"lastModified" : "2017-08-15T16:54:15.677Z"
},
"userName" : "marcus@stoicism.com",
"name" : {},
"emails" : [ {
"value" : "marcus@stoicism.com",
"primary" : false
} ],
"groups" : [ {
"value" : "ac2ab20e-0a2d-4b68-82e4-817ee6b258b4",
"display" : "philosophy.read",
"type" : "DIRECT"
}, {
"value" : "110b2434-4a30-439b-b5fc-f4cf47fc04f0",
"display" : "philosophy.write",
"type" : "DIRECT"
}],
"approvals" : [ {
"userId" : "fb5f32e1-5cb3-49e6-93df-6df9c8c8bd70",
"clientId" : "shinyclient",
"scope" : "philosophy.read",
"status" : "APPROVED",
"lastUpdatedAt" : "2017-08-15T16:54:15.765Z",
"expiresAt" : "2017-08-15T16:54:25.765Z"
}, {
"userId" : "fb5f32e1-5cb3-49e6-93df-6df9c8c8bd70",
"clientId" : "identity",
"scope" : "uaa.user",
"status" : "APPROVED",
"lastUpdatedAt" : "2017-08-15T16:54:45.767Z",
"expiresAt" : "2017-08-15T16:54:45.767Z"
} ],
"phoneNumbers" : [ {
"value" : "5555555555"
} ],
"active" : true,
"verified" : true,
"origin" : "uaa",
"zoneId" : "uaa",
"passwordLastModified" : "2017-08-15T16:54:15.000Z",
"previousLogonTime" : 1502816055768,
"lastLogonTime" : 1502816055768,
"schemas" : [ "urn:scim:schemas:core:1.0" ]
}`

const DrSeussUserResponse = `{
"id" : "fb5f32e1-5cb3-49e6-93df-6df9c8c8bd70",
"externalId" : "seuss-user",
Expand Down

0 comments on commit 8626b94

Please sign in to comment.