github.com/arunkumar7540/cli@v6.45.0+incompatible/integration/v6/isolated/set_org_role_command_test.go (about) 1 package isolated 2 3 import ( 4 . "github.com/onsi/ginkgo" 5 . "github.com/onsi/gomega" 6 . "github.com/onsi/gomega/gbytes" 7 . "github.com/onsi/gomega/gexec" 8 9 "code.cloudfoundry.org/cli/integration/helpers" 10 ) 11 12 var _ = Describe("set-org-role command", func() { 13 Describe("help text and argument validation", func() { 14 When("-h is passed", func() { 15 It("prints the help text", func() { 16 session := helpers.CF("set-org-role", "-h") 17 Eventually(session).Should(Say(`NAME:`)) 18 Eventually(session).Should(Say(`\s+set-org-role - Assign an org role to a user`)) 19 Eventually(session).Should(Say(`USAGE:`)) 20 Eventually(session).Should(Say(`\s+cf set-org-role USERNAME ORG ROLE \[--client\]`)) 21 Eventually(session).Should(Say(`ROLES:`)) 22 Eventually(session).Should(Say(`\s+'OrgManager' - Invite and manage users, select and change plans, and set spending limits`)) 23 Eventually(session).Should(Say(`\s+'BillingManager' - Create and manage the billing account and payment info`)) 24 Eventually(session).Should(Say(`\s+'OrgAuditor' - Read-only access to org info and reports`)) 25 Eventually(session).Should(Say("OPTIONS:")) 26 Eventually(session).Should(Say(`--client\s+Treat USERNAME as the client-id of a \(non-user\) service account`)) 27 Eventually(session).Should(Say(`SEE ALSO:`)) 28 Eventually(session).Should(Say(`\s+org-users, set-space-role`)) 29 Eventually(session).Should(Exit(0)) 30 }) 31 }) 32 33 When("not enough arguments are provided", func() { 34 It("prints an error and help text", func() { 35 session := helpers.CF("set-org-role", "foo", "bar") 36 Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `ROLE` was not provided")) 37 Eventually(session).Should(Say("NAME:")) 38 Eventually(session).Should(Say(" set-org-role - Assign an org role to a user")) 39 Eventually(session).Should(Say("USAGE:")) 40 Eventually(session).Should(Say(`\s+cf set-org-role USERNAME ORG ROLE \[--client\]`)) 41 Eventually(session).Should(Say("ROLES:")) 42 Eventually(session).Should(Say(" 'OrgManager' - Invite and manage users, select and change plans, and set spending limits")) 43 Eventually(session).Should(Say(" 'BillingManager' - Create and manage the billing account and payment info")) 44 Eventually(session).Should(Say(" 'OrgAuditor' - Read-only access to org info and reports")) 45 Eventually(session).Should(Say("OPTIONS:")) 46 Eventually(session).Should(Say(`--client\s+Treat USERNAME as the client-id of a \(non-user\) service account`)) 47 Eventually(session).Should(Say("SEE ALSO:")) 48 Eventually(session).Should(Say(" org-users, set-space-role")) 49 Eventually(session).Should(Exit(1)) 50 }) 51 }) 52 53 When("too many arguments are provided", func() { 54 It("prints an error and help text", func() { 55 session := helpers.CF("set-org-role", "some-user", "some-org", "OrgManager", "some-extra-argument") 56 Eventually(session).Should(Say(`Incorrect Usage. Requires USERNAME, ORG, ROLE as arguments`)) 57 Eventually(session).Should(Say(`NAME:`)) 58 Eventually(session).Should(Say(`\s+set-org-role - Assign an org role to a user`)) 59 Eventually(session).Should(Say(`USAGE:`)) 60 Eventually(session).Should(Say(`\s+cf set-org-role USERNAME ORG ROLE \[--client\]`)) 61 Eventually(session).Should(Say(`ROLES:`)) 62 Eventually(session).Should(Say(`\s+'OrgManager' - Invite and manage users, select and change plans, and set spending limits`)) 63 Eventually(session).Should(Say(`\s+'BillingManager' - Create and manage the billing account and payment info`)) 64 Eventually(session).Should(Say(`\s+'OrgAuditor' - Read-only access to org info and reports`)) 65 Eventually(session).Should(Say("OPTIONS:")) 66 Eventually(session).Should(Say(`--client\s+Treat USERNAME as the client-id of a \(non-user\) service account`)) 67 Eventually(session).Should(Exit(1)) 68 }) 69 }) 70 }) 71 72 When("the user is logged in", func() { 73 var orgName string 74 var username string 75 76 BeforeEach(func() { 77 helpers.LoginCF() 78 orgName = ReadOnlyOrg 79 username, _ = helpers.CreateUser() 80 }) 81 82 When("the --client flag is passed", func() { 83 When("the targeted user is actually a client", func() { 84 var clientID string 85 86 BeforeEach(func() { 87 clientID, _ = helpers.SkipIfClientCredentialsNotSet() 88 }) 89 90 It("sets the org role for the client", func() { 91 session := helpers.CF("set-org-role", clientID, orgName, "OrgManager", "--client") 92 Eventually(session).Should(Say("Assigning role OrgManager to user %s in org %s as admin...", clientID, orgName)) 93 Eventually(session).Should(Say("OK")) 94 Eventually(session).Should(Exit(0)) 95 }) 96 97 When("the active user lacks permissions to look up clients", func() { 98 BeforeEach(func() { 99 helpers.SwitchToOrgRole(orgName, "OrgManager") 100 }) 101 102 It("prints an appropriate error and exits 1", func() { 103 session := helpers.CF("set-org-role", "notaclient", orgName, "OrgManager", "--client") 104 Eventually(session).Should(Say("FAILED")) 105 Eventually(session).Should(Say("Server error, status code: 403: Access is denied. You do not have privileges to execute this command.")) 106 Eventually(session).Should(Exit(1)) 107 }) 108 }) 109 }) 110 111 When("the targeted client does not exist", func() { 112 var badClientID string 113 114 BeforeEach(func() { 115 badClientID = "nonexistent-client" 116 }) 117 118 It("fails with an appropriate error message", func() { 119 session := helpers.CF("set-org-role", badClientID, orgName, "OrgManager", "--client") 120 Eventually(session).Should(Say("FAILED")) 121 Eventually(session).Should(Say("Client nonexistent-client not found")) 122 Eventually(session).Should(Exit(1)) 123 }) 124 }) 125 }) 126 127 When("the org and user both exist", func() { 128 When("the passed role is all lowercase", func() { 129 It("sets the org role for the user", func() { 130 session := helpers.CF("set-org-role", username, orgName, "orgauditor") 131 Eventually(session).Should(Say("Assigning role OrgAuditor to user %s in org %s as admin...", username, orgName)) 132 Eventually(session).Should(Say("OK")) 133 Eventually(session).Should(Exit(0)) 134 }) 135 }) 136 137 It("sets the org role for the user", func() { 138 session := helpers.CF("set-org-role", username, orgName, "OrgAuditor") 139 Eventually(session).Should(Say("Assigning role OrgAuditor to user %s in org %s as admin...", username, orgName)) 140 Eventually(session).Should(Say("OK")) 141 Eventually(session).Should(Exit(0)) 142 }) 143 144 When("the logged in user has insufficient permissions", func() { 145 BeforeEach(func() { 146 helpers.SwitchToOrgRole(orgName, "OrgAuditor") 147 }) 148 149 It("prints out the error message from CC API and exits 1", func() { 150 session := helpers.CF("set-org-role", username, orgName, "OrgAuditor") 151 Eventually(session).Should(Say("FAILED")) 152 Eventually(session).Should(Say("Server error, status code: 403, error code: 10003, message: You are not authorized to perform the requested action")) 153 Eventually(session).Should(Exit(1)) 154 }) 155 }) 156 157 When("the user already has the desired role", func() { 158 BeforeEach(func() { 159 session := helpers.CF("set-org-role", username, orgName, "OrgManager") 160 Eventually(session).Should(Say("Assigning role OrgManager to user %s in org %s as admin...", username, orgName)) 161 Eventually(session).Should(Exit(0)) 162 }) 163 164 It("is idempotent", func() { 165 session := helpers.CF("set-org-role", username, orgName, "OrgManager") 166 Eventually(session).Should(Say("Assigning role OrgManager to user %s in org %s as admin...", username, orgName)) 167 Eventually(session).Should(Exit(0)) 168 }) 169 }) 170 171 When("the specified role is invalid", func() { 172 It("prints a useful error, prints help text, and exits 1", func() { 173 session := helpers.CF("set-org-role", username, orgName, "NotARealRole") 174 Eventually(session.Err).Should(Say(`Incorrect Usage: ROLE must be "OrgManager", "BillingManager" and "OrgAuditor"`)) 175 Eventually(session).Should(Say(`NAME:`)) 176 Eventually(session).Should(Say(`\s+set-org-role - Assign an org role to a user`)) 177 Eventually(session).Should(Say(`USAGE:`)) 178 Eventually(session).Should(Say(`\s+set-org-role USERNAME ORG ROLE`)) 179 Eventually(session).Should(Say(`ROLES:`)) 180 Eventually(session).Should(Say(`\s+'OrgManager' - Invite and manage users, select and change plans, and set spending limits`)) 181 Eventually(session).Should(Say(`\s+'BillingManager' - Create and manage the billing account and payment info`)) 182 Eventually(session).Should(Say(`\s+'OrgAuditor' - Read-only access to org info and reports`)) 183 Eventually(session).Should(Say(`SEE ALSO:`)) 184 Eventually(session).Should(Say(`\s+org-users, set-space-role`)) 185 Eventually(session).Should(Exit(1)) 186 }) 187 }) 188 }) 189 190 When("the org does not exist", func() { 191 It("prints an appropriate error and exits 1", func() { 192 session := helpers.CF("set-org-role", username, "not-exists", "OrgAuditor") 193 Eventually(session).Should(Say("FAILED")) 194 Eventually(session).Should(Say("Organization not-exists not found")) 195 Eventually(session).Should(Exit(1)) 196 }) 197 }) 198 199 When("the user does not exist", func() { 200 It("prints an appropriate error and exits 1", func() { 201 session := helpers.CF("set-org-role", "not-exists", orgName, "OrgAuditor") 202 Eventually(session).Should(Say("Assigning role OrgAuditor to user not-exists in org %s as admin...", orgName)) 203 Eventually(session).Should(Say("FAILED")) 204 Eventually(session).Should(Say("Server error, status code: 404, error code: 20003, message: The user could not be found: not-exists")) 205 Eventually(session).Should(Exit(1)) 206 }) 207 }) 208 }) 209 210 When("the user is not logged in", func() { 211 BeforeEach(func() { 212 helpers.LogoutCF() 213 }) 214 215 It("reports that the user is not logged in", func() { 216 session := helpers.CF("set-org-role", "some-user", "some-org", "BillingManager") 217 Eventually(session).Should(Say("FAILED")) 218 Eventually(session).Should(Say("Not logged in. Use 'cf login' to log in.")) 219 Eventually(session).Should(Exit(1)) 220 }) 221 }) 222 })