a3e3cd2b8e63315e56b2786715a3d4e526075162
[integration/test.git] / csit / suites / aaa / idmlite / 010_CRUD_Rest_CommandsTests.robot
1 *** Settings ***
2 Documentation     Basic REST AAA Tests for IdMLight
3 ...
4 ...               Copyright (c) 2015 Hewlett-Packard Development Company, L.P. and others. All rights reserved.
5 ...
6 ...               This program and the accompanying materials are made available under the
7 ...               terms of the Eclipse Public License v1.0 which accompanies this distribution,
8 ...               and is available at http://www.eclipse.org/legal/ep1-v10.html
9 Suite Setup       IdMLight Suite Setup
10 Suite Teardown    IdMLight Suite Teardown
11 Library           Collections
12 Library           RequestsLibrary
13 Library           OperatingSystem
14 Library           String
15 Library           HttpLibrary.HTTP
16 Library           DateTime
17 Library           ../../../libraries/Common.py
18 Library           ../../../libraries/AAAJsonUtils.py
19 Resource          ../../../libraries/Utils.robot
20 Variables         ../../../variables/Variables.py
21 Resource          ../../../libraries/AAAKeywords.robot
22
23 *** Variables ***
24 # port is fixed in Jetty configuration, as well
25 ${URI}            http://${CONTROLLER}:8282
26 # create lists for Domains, Roles and Users - that can be cleaned up upon Teardown
27 @{cleanup_domain_list}
28 @{cleanup_role_list}
29 @{cleanup_user_list}
30 @{cleanup_grant_list}
31 # will modify value in Setup and use throughout the code
32 ${HEADERS}        ${EMPTY}
33
34 *** Test Cases ***
35 Test Post New Domain
36     [Documentation]    Create a domain using REST POST command.
37     # create a temp name, set it to domainName
38     ${domainName}=    Create Random Name    domain-Other
39     # Create the new domain, initialize some values to test against
40     ${domaindesc}=    Set Variable    "testdomain other"
41     ${domainstatus}=    Set Variable    "true"
42     # Have to escape the quotes, need quotes to make the POST work properly
43     ${data}=    Set Variable    {"description":${domaindesc},"domainid":"7","name":\"${domainName}\","enabled":${domainstatus}}
44     Log    ${data}
45     # now post it
46     ${domain}=    Post New Domain    ${domainName}    ${data}
47     Log    ${domain}
48     ${domainid}=    Parse Item From Blob By Offset    ${domain}    0
49     Log    ${domainid}
50     # get the domain to verify
51     ${fetched_domain}=    Get Specific Domain    ${domainid}
52     # add new domain json string to the cleanup list for later cleanup
53     Append To List    ${cleanup_domain_list}    ${fetched_domain}
54     # count the number of domainid's that appear in this block of JSON
55     ${depth}=    Fieldcount    ${fetched_domain}    "domainid"
56     ${fetchedDomStatus}=    Get Domain State By Domainid    ${domain}    ${domainid}    ${depth}
57     ${fetchedDomDesc}=    Get Domain Description By Domainid    ${domain}    ${domainid}    ${depth}
58     # Set Test Disposition based on comparison of what was posted and what was fetched
59     ${testdisposition}=    Set Variable If    '${fetched_domain}' == '${domain}'    '${fetchedDomStatus}' == '${domainstatus}'    '${fetchedDomDesc}' == '${domaindesc}'
60     Log    ${testdisposition}
61
62 Test Get Domains
63     [Documentation]    Exercise REST GET command to get all domains.
64     # rely on the creation of a test role in the Setup routine
65     # pop item off of end of the cleanup list, for use (does not alter list)
66     Log    ${cleanup_domain_list}
67     ${domain_item}=    Get From List    ${cleanup_domain_list}    -1
68     Log    ${domain_item}
69     # parse out the domainid from the domain info we just grabbed
70     ${domainid}=    Parse Item From Blob By Offset    ${domain_item}    0
71     Log    ${domainid}
72     # parse out the name from the same info
73     ${domainname}=    Parse Item From Blob By Offset    ${domain_item}    1
74     Log    ${domainname}
75     # get the entire dump of created domains
76     ${content}=    Get Domains
77     # parse through that massive blob and get the individual name created in Setup
78     ${node_count}=    Nodecount    ${content}    domains    domainid
79     ${domainid}=    Convert To Integer    ${domainid}
80     # Get the domain name from the database, looking it up by its domainid
81     ${domainentry}=    Get Domain Name By Domainid    ${content}    ${domainid}    ${node_count}
82     Log    ${domainentry}
83     # compare to see if the parsed user id matches the one we grabbed from list
84     Should Be Equal    ${domainentry}    ${domainname}
85
86 Test Get Specific Domain
87     [Documentation]    Get a specific domain using REST GET command.
88     # from the pre-created (see Setup routine) list, grab a domain id for testing
89     ${listlength}=    Get Length    ${cleanup_domain_list}
90     # pop item off of end of the list, for use (does not alter list)
91     Log    ${cleanup_domain_list}
92     ${domain_item}=    Get From List    ${cleanup_domain_list}    -1
93     ${item}=    Pop Name Off Json    ${domain_item}
94     # convert this crap to unicode
95     # ${item}=    Convert To String    ${item}
96     Log    ${item}
97     # make a GET call to find the material we want to delete
98     ${domains}=    Get Domains
99     # convert name on the list to an ID, by which we delete this stuff
100     ${node_count}=    Nodecount    ${domains}    domains    domainid
101     ${node_count}=    Convert To Integer    ${node_count}
102     ${domainid}=    Get Domain Id By Domainname    ${domains}    ${item}    ${node_count}
103     # now, get the specific domain by it's domainid
104     ${domaininfo}=    Get Specific Domain    ${domainid}
105     Should Contain    ${domaininfo}    ${item}
106     Log    ${domaininfo}
107
108 Test Update Specific Domain
109     [Documentation]    Update a specific domain using REST PUT command.
110     # rely on the creation of a test domain in the Setup routine
111     # pop item off of end of the list, for use (does not alter list)
112     Log    ${cleanup_domain_list}
113     ${domain_item}=    Get From List    ${cleanup_domain_list}    -1
114     Log    ${domain_item}
115     # parse out the domain id from the domain info we just grabbed
116     ${domid}=    Parse Item From Blob By Offset    ${domain_item}    0
117     Log    ${domid}
118     # parse out the name from the same info
119     ${domname}=    Parse Item From Blob By Offset    ${domain_item}    1
120     Log    ${domname}
121     ${data}=    Set Variable    {"name":"MasterTest Domain"}
122     Update Specific Domain    ${data}    ${domid}
123     ${domname}=    Get Specific Domain Name    ${domid}
124     Log    ${domname}
125     ${z}=    Split String    ${data}    :
126     ${dname}=    Get From List    ${z}    1
127     ${dname}=    Replace String    ${dname}    "    ${EMPTY}
128     ${dname}=    Replace String    ${dname}    }    ${EMPTY}
129     Log    ${dname}
130     ${modified_name}=    Pop Name Off Json    ${domname}
131     Log    ${modified_name}
132     Should Be Equal    ${dname}    ${modified_name}
133
134 Test Delete Domain
135     [Documentation]    Delete a specific domain using REST DELETE command.
136     # create a temporary test domain
137     ${tempdomain}=    Create Random Name    temp-domain-name
138     ${domaindata}=    Set Variable    {"description":"temporary test domain","domainid":"1","name":"${tempdomain}","enabled":"true"}
139     # Post that temp domain
140     ${newdomain}=    Post New Domain    ${tempdomain}    ${domaindata}
141     Log    ${newdomain}
142     # parse out the domain-id from the domain info we just created
143     ${domainid}=    Parse Item From Blob By Offset    ${newdomain}    0
144     Log    ${domainid}
145     # now wipe if off the map
146     Delete Domain    ${domainid}
147     # we should not be able to fetch this domain from the database of domains...should fail...
148     ${content}=    Check Specific Id Does Not Exist    domain    ${domainid}
149     Log    ${content}
150
151 Test Get Users
152     [Documentation]    Exercise REST GET command for obtaining all users.
153     # rely on the creation of a test user in the Setup routine
154     # pop item off of end of the list, for use (does not alter list)
155     Log    ${cleanup_user_list}
156     ${user_item}=    Get From List    ${cleanup_user_list}    -1
157     Log    ${user_item}
158     # parse out the userid from the user info we just grabbed
159     ${userid}=    Parse Item From Blob By Offset    ${user_item}    0
160     Log    ${userid}
161     # parse out the name from the same info
162     ${username}=    Parse Item From Blob By Offset    ${user_item}    1
163     Log    ${username}
164     # get the entire blob of users
165     ${content}=    Get Users
166     # parse through that massive blob and get the individual name
167     ${node_count}=    Nodecount    ${content}    users    userid
168     ${userid}=    Convert To Integer    ${userid}
169     ${userentry}=    Get User Name By Userid    ${content}    ${userid}    ${node_count}
170     Log    ${userentry}
171     # compare to see if the parsed user id matches the one we grabbed from list
172     Should Be Equal    ${userentry}    ${username}
173
174 Test Get Specific User
175     [Documentation]    Exercise REST GET command to obtain a specific user.
176     # from the pre-created (see Setup routine) list, grab a user id for testing
177     ${listlength}=    Get Length    ${cleanup_user_list}
178     # pop item off of end of the list, for use (does not alter list)
179     Log    ${cleanup_user_list}
180     ${user_item}=    Get From List    ${cleanup_user_list}    -1
181     ${item}=    Pop Name Off Json    ${user_item}
182     # convert this to unicode
183     # ${item}=    Convert To String    ${item}
184     Log    ${item}
185     # parse out the userid from the user info we just grabbed
186     ${userid}=    Parse Item From Blob By Offset    ${user_item}    0
187     Log    ${userid}
188     # parse out the name from the same info
189     ${username}=    Parse Item From Blob By Offset    ${user_item}    1
190     Log    ${username}
191     # make a GET call to find the material we want
192     ${content}=    Get Specific User    ${userid}
193     # parse out the user name from the content we just fetched
194     ${fetched_username}=    Parse Item From Blob By Offset    ${content}    1
195     Log    ${fetched_username}
196     # compare to see if the parsed user name matches the one we grabbed from list
197     Should Contain    ${fetched_username}    ${username}
198
199 Test Update User
200     [Documentation]    Exercise PUT command against an existing User ID.
201     # pop item off of end of the list, for use (does not alter list)
202     Log    ${cleanup_user_list}
203     ${user_item}=    Get From List    ${cleanup_user_list}    -1
204     Log    ${user_item}
205     # parse out the user-id from the user info we just created
206     ${userid}=    Parse Item From Blob By Offset    ${user_item}    0
207     Log    ${userid}
208     # update the information for the userid
209     ${testusername}=    Create Random Name    force-accomplish
210     ${data}=    Set Variable    {"description":"sample test description", "name":"${testusername}"}
211     ${content}=    Update Specific User    ${data}    ${userid}
212     Log    ${testusername}
213     # now, make a GET call to find the material we modified
214     ${existing_useritem}=    Get Specific User    ${userid}
215     # parse out the name from the existing userinfo
216     ${expected_username}=    Parse Item From Blob By Offset    ${existing_useritem}    1
217     Log    ${expected_username}
218     # compare to see if the GOTTEN user id matches the one we grabbed from list
219     Should Be Equal    ${expected_username}    ${testusername}
220
221 Test Post New User
222     [Documentation]    Test the POST command to create a new user.
223     # create information for a new role (for the test)
224     ${testusername}=    Create Random Name    Darth-Maul
225     ${data}=    Set Variable    {"description":"sample user description", "name":"${testusername}", "userid":1}
226     Log    ${testusername}
227     # Post this puppy
228     ${content}=    Post New User    ${testusername}    ${data}
229     # parse out the userid from the content we just created
230     ${userid}=    Parse Item From Blob By Offset    ${content}    0
231     Log    ${userid}
232     # now go GET the userid info and compare to the name we fabricated
233     ${existing_useritem}=    Get Specific User    ${userid}
234     ${expected_username}=    Parse Item From Blob By Offset    ${existing_useritem}    1
235     Log    ${expected_username}
236     # compare to see if the GOTTEN role id matches the one we grabbed from list
237     Should Be Equal    ${expected_username}    ${testusername}
238
239 Test Delete User
240     [Documentation]    Exercise REST command for DELETE user command.
241     # create a user and then delete it.    Use Get to verify it's gone
242     # create information for a new user (for the test)
243     ${testusername}=    Create Random Name    force-user
244     ${data}=    Set Variable    {"description":"sample test description", "name":"${testusername}", "userid":1}
245     Log    ${testusername}
246     # Post this disposable user
247     ${content}=    Post New User    ${testusername}    ${data}
248     # parse out the user-id from the content we just created
249     ${userid}=    Parse Item From Blob By Offset    ${content}    0
250     Log    ${userid}
251     # now delete it...
252     ${content2}=    Delete User    ${userid}
253     # should fail...
254     ${content}=    Check Specific Id Does Not Exist    user    ${userid}
255     Log    ${content}
256
257 Test Get Specific Role
258     [Documentation]    Exercise REST command for roles GET command.
259     # from the pre-created (see Setup routine) list, grab a role id for testing
260     ${listlength}=    Get Length    ${cleanup_role_list}
261     # pop item off of end of the list, for use (does not alter list)
262     Log    ${cleanup_role_list}
263     ${role_item}=    Get From List    ${cleanup_role_list}    -1
264     Log    ${role_item}
265     # parse out the role-id from the role info we just created
266     ${roleid}=    Parse Item From Blob By Offset    ${roleitem}    0
267     Log    ${roleid}
268     # make a GET call to find the material we want
269     ${existing_roleitem}=    Get Specific Role    ${roleid}
270     # parse out the expected role-id from the content we just created
271     ${eroleid}=    Parse Item From Blob By Offset    ${existing_roleitem}    0
272     Log    ${eroleid}
273     # compare to see if the GOTTEN role id matches the one we grabbed from list
274     Should Be Equal    ${eroleid}    ${roleid}
275
276 Test Get Roles
277     [Documentation]    Exercise REST command for roles GET command.
278     # rely on the creation of a test role in the Setup routine
279     # pop item off of end of the list, for use (does not alter list)
280     Log    ${cleanup_role_list}
281     ${role_item}=    Get From List    ${cleanup_role_list}    -1
282     Log    ${role_item}
283     # parse out the role-id from the info we just grabbed
284     ${roleid}=    Parse Item From Blob By Offset    ${role_item}    0
285     Log    ${roleid}
286     # parse out the name from the same info
287     ${rolename}=    Parse Item From Blob By Offset    ${role_item}    1
288     Log    ${rolename}
289     # get the entire blob of roles
290     ${content}=    Get Roles
291     # parse through that massive blob and get the individual name
292     ${node_count}=    Nodecount    ${content}    roles    roleid
293     ${roleid}=    Convert To Integer    ${roleid}
294     ${roleentry}=    Get Role Name By Roleid    ${content}    ${roleid}    ${node_count}
295     Log    ${roleentry}
296     # compare to see if the parsed user id matches the one we grabbed from list
297     Should Be Equal    ${roleentry}    ${rolename}
298
299 Test Update Role
300     [Documentation]    Exercise PUT command against an existing Role ID.
301     # pop item off of end of the list, for use (does not alter list)
302     Log    ${cleanup_role_list}
303     ${role_item}=    Get From List    ${cleanup_role_list}    -1
304     Log    ${role_item}
305     # parse out the role-id from the role info we just created
306     ${roleid}=    Parse Item From Blob By Offset    ${role_item}    0
307     Log    ${roleid}
308     # update the information for the roleid
309     ${testrolename}=    Create Random Name    force-accomplish
310     ${data}=    Set Variable    {"description":"sample test description", "name":"${testrolename}"}
311     ${content}=    Update Specific Role    ${data}    ${roleid}
312     Log    ${testrolename}
313     # now, make a GET call to find the material we modified
314     ${existing_roleitem}=    Get Specific Role    ${roleid}
315     # parse out the name from the same info
316     ${expected_rolename}=    Parse Item From Blob By Offset    ${existing_roleitem}    1
317     Log    ${expected_rolename}
318     # compare to see if the GOTTEN role id matches the one we grabbed from list
319     Should Be Equal    ${expected_rolename}    ${testrolename}
320
321 Test Post New Role
322     [Documentation]    Exercise POST command to create a new Role.
323     # create information for a new role (for the test)
324     ${testrolename}=    Create Random Name    force-brother-cousin
325     ${data}=    Set Variable    {"description":"sample test description", "name":"${testrolename}", "roleid":1}
326     Log    ${testrolename}
327     # Post this puppy
328     ${content}=    Post New Role    ${data}
329     # parse out the role-id from the content we just created
330     ${roleid}=    Parse Item From Blob By Offset    ${content}    0
331     Log    ${roleid}
332     # now got GET the roleid info and compare to the name we fabricated
333     # and parse out role name
334     ${existing_roleitem}=    Get Specific Role    ${roleid}
335     ${expected_rolename}=    Parse Item From Blob By Offset    ${content}    1
336     Log    ${expected_rolename}
337     # compare to see if the GOTTEN role id matches the one we grabbed from list
338     Should Be Equal    ${expected_rolename}    ${testrolename}
339
340 Test Delete Role
341     [Documentation]    Exercise REST command for DELETE role command.
342     # create a role and then delete it.    Use Get to verify it's gone
343     # create information for a new role (for the test)
344     ${testrolename}=    Create Random Name    force-usurper
345     ${data}=    Set Variable    {"description":"sample test description", "name":"${testrolename}", "roleid":1}
346     Log    ${testrolename}
347     # Post this disposable role
348     ${content}=    Post New Role    ${data}
349     # parse out the role-id from the content we just created
350     ${roleid}=    Parse Item From Blob By Offset    ${content}    0
351     Log    ${roleid}
352     # now delete it...
353     ${content2}=    Delete Role    ${roleid}
354     # should fail...
355     ${content}=    Check Specific Id Does Not Exist    role    ${roleid}
356     Log    ${content}
357
358 Test Grant Role To Domain And User
359     [Documentation]    Test the POST of a Role to Domain and User
360     # rely on the creation of a test role, user and domain in the Setup routine
361     # pop item off of end of the list, for use (does not alter list)
362     ${role_item}=    Get From List    ${cleanup_role_list}    -1
363     Log    ${role_item}
364     ${user_item}=    Get From List    ${cleanup_user_list}    -1
365     Log    ${user_item}
366     ${domain_item}=    Get From List    ${cleanup_domain_list}    -1
367     Log    ${domain_item}
368     # parse out the roleid from the role info we just grabbed
369     ${roleid}=    Parse Item From Blob By Offset    ${role_item}    0
370     Log    ${roleid}
371     # parse out the name from the same info
372     ${rolename}=    Parse Item From Blob By Offset    ${role_item}    1
373     Log    ${rolename}
374     # parse out the userid from the user info we just grabbed
375     ${userid}=    Parse Item From Blob By Offset    ${user_item}    0
376     Log    ${userid}
377     # parse out the name from the same info
378     ${username}=    Parse Item From Blob By Offset    ${user_item}    1
379     Log    ${username}
380     # parse out the domain-id from the domain info we just grabbed
381     ${domainid}=    Parse Item From Blob By Offset    ${domain_item}    0
382     Log    ${domainid}
383     # parse out the name from the same info
384     ${domainname}=    Parse Item From Blob By Offset    ${domain_item}    1
385     Log    ${domainname}
386     # generate the data payload that we wish to post
387     ${data}=    Set Variable    {"roleid":"${roleid}", "description":"fabricated test roleid"}
388     # post this monster
389     ${content}=    Post Role To Domain And User    ${data}    ${domainid}    ${userid}
390     # add new json string to the cleanup list for later cleanup
391     Append To List    ${cleanup_grant_list}    ${content}
392     Should Contain    ${content}    ${domainid}
393     Should Contain    ${content}    ${roleid}
394     Should Contain    ${content}    ${userid}
395
396 *** Keywords ***
397 IdMLight Suite Setup
398     Log    Suite Setup
399     # create a domain, role and user for testing.
400     ${HEADERS}=    Create Dictionary    Content-Type=application/json
401     Log    ${HEADERS}
402     Set Global Variable    ${HEADERS}
403     # create a name to use in each case
404     ${testdomain}=    Create Random Name    Alderaan
405     Log    ${testdomain}
406     ${testuser}=    Create Random Name    Leia
407     Log    ${testuser}
408     ${testrole}=    Create Random Name    Force-User
409     Log    ${testrole}
410     # now create the domain, role and userid
411     # create the test domain
412     Create Session    httpbin    ${URI}
413     ${domaindata}=    Set Variable    {"description":"planetary domain","domainid":"7","name":"${testdomain}","enabled":"true"}
414     ${newdomain}=    Post New Domain    ${testdomain}    ${domaindata}
415     Log    ${newdomain}
416     # add new domain name to the cleanup list for later cleanup
417     Append To List    ${cleanup_domain_list}    ${newdomain}
418     # now create the test user
419     ${userdata}=    Set Variable    {"description":"User-of-the-Force","name":"${testuser}","enabled":"true"}
420     ${newuser}=    Post New User    ${testuser}    ${userdata}
421     Log    ${newuser}
422     # add new user name to the cleanup list for later cleanup
423     Append To List    ${cleanup_user_list}    ${newuser}
424     # now create the test role
425     ${roledata}=    Set Variable    {"name":"${testrole}","description":"Force User"}
426     ${newrole}=    Post New Role    ${roledata}
427     # add new role name to the cleanup list for later cleanup
428     Append To List    ${cleanup_role_list}    ${newrole}
429     #
430     # return the three item names to the caller of setup
431     [Return]    ${newdomain}    ${newuser}    ${newrole}
432
433 IdMLight Suite Teardown
434     Log    Suite Teardown
435     ${ELEMENT}=    Create Session    httpbin    ${URI}
436     # if the test domain, role or user exists, wipe it out.
437     : FOR    ${ELEMENT}    IN    @{cleanup_domain_list}
438     \    ${ELEMENT}    Replace String    ${ELEMENT}    ${SPACE}    ${EMPTY}
439     \    Log    ${ELEMENT}
440     \    # split it up to get the domainid
441     \    ${x}=    Split String    ${ELEMENT}    ,
442     \    ${y}=    Get From List    ${x}    0
443     \    ${z}=    Split String    ${y}    :
444     \    ${domainid}=    Get From List    ${z}    1
445     \    Log    ${domainid}
446     \    # convert name on the list to an ID, by which we delete this stuff
447     \    Delete Domain    ${domainid}
448     Log    ${cleanup_domain_list}
449     # Cleanup roles that were created during testing
450     : FOR    ${ELEMENT}    IN    @{cleanup_role_list}
451     \    Log    ${ELEMENT}
452     \    ${ELEMENT}    Replace String    ${ELEMENT}    ${SPACE}    ${EMPTY}
453     \    Log    ${ELEMENT}
454     \    # split it up to get the roleid
455     \    ${x}=    Split String    ${ELEMENT}    ,
456     \    ${y}=    Get From List    ${x}    0
457     \    ${z}=    Split String    ${y}    :
458     \    ${roleid}=    Get From List    ${z}    1
459     \    Log    ${roleid}
460     \    # convert name on the list to an ID, by which we delete this stuff
461     \    Delete Role    ${roleid}
462     Log    ${cleanup_role_list}
463     # Cleanup users that were created during testing
464     : FOR    ${ELEMENT}    IN    @{cleanup_user_list}
465     \    Log    ${ELEMENT}
466     \    ${ELEMENT}    Replace String    ${ELEMENT}    ${SPACE}    ${EMPTY}
467     \    Log    ${ELEMENT}
468     \    # split it up to get the roleid
469     \    ${x}=    Split String    ${ELEMENT}    ,
470     \    ${y}=    Get From List    ${x}    0
471     \    ${z}=    Split String    ${y}    :
472     \    ${userid}=    Get From List    ${z}    1
473     \    Log    ${userid}
474     \    Delete User    ${userid}
475     Log    ${cleanup_user_list}
476     Delete All Sessions
477
478 Check Specific Id Does Not Exist
479     [Arguments]    ${area_to_look}    ${id}
480     [Documentation]    Execute GET command on specified single id
481     # the ITEM is the area to look under...    users, domains, roles, etc
482     ${n1}=    Set Variable    auth/v1/${area_to_look}/${id}
483     # do the actual get
484     ${resp}    RequestsLibrary.Get    httpbin    ${n1}    headers=${HEADERS}
485     Should Be Equal As Strings    ${resp.status_code}    404
486     ${id_string}=    Convert To String    ${id}
487     Should Contain    ${resp.content}    ${id_string}
488     [Return]    ${resp.content}
489
490 Get Specific Domain
491     [Arguments]    ${domainid}
492     [Documentation]    Execute GET command on specified single domain
493     ${n1}=    Set Variable    auth/v1/domains/${domainid}
494     ${resp}    RequestsLibrary.Get    httpbin    ${n1}    headers=${HEADERS}
495     Should Be Equal As Strings    ${resp.status_code}    200
496     ${domainid_string}=    Convert To String    ${domainid}
497     Should Contain    ${resp.content}    ${domainid_string}
498     [Return]    ${resp.content}
499
500 Get Specific Domain Name
501     [Arguments]    ${domainid}
502     [Documentation]    Execute GET command on specified single domain
503     ${n1}=    Set Variable    auth/v1/domains/${domainid}
504     ${resp}    RequestsLibrary.Get    httpbin    ${n1}    headers=${HEADERS}
505     Should Contain    ${resp.content}    ${domainid}
506     Log    ${resp.content}
507     [Return]    ${resp.content}
508
509 Get Specific Role
510     [Arguments]    ${roleid}
511     [Documentation]    Exercise REST command to GET a specific role, based on role-id
512     ${n1}=    Set Variable    auth/v1/roles/${roleid}
513     ${resp}    RequestsLibrary.Get    httpbin    ${n1}    headers=${HEADERS}
514     Should Be Equal As Strings    ${resp.status_code}    200
515     Should Contain    ${resp.content}    ${roleid}
516     [Return]    ${resp.content}
517
518 Get Domains
519     [Documentation]    Execute getdomains GET command.
520     ${n1}=    Set Variable    auth/v1/domains
521     ${resp}    RequestsLibrary.Get    httpbin    ${n1}    headers=${HEADERS}
522     Should Be Equal As Strings    ${resp.status_code}    200
523     Should Contain    ${resp.content}    "domains"
524     [Return]    ${resp.content}
525
526 Get Roles
527     [Documentation]    Execute GET command to obtain list of roles.
528     ${n1}=    Set Variable    auth/v1/roles
529     ${resp}    RequestsLibrary.Get    httpbin    ${n1}    headers=${HEADERS}
530     Should Be Equal As Strings    ${resp.status_code}    200
531     Should Contain    ${resp.content}    "roles"
532     [Return]    ${resp.content}
533
534 Get Specific User
535     [Arguments]    ${user}
536     [Documentation]    Exercise REST command for users GET command.
537     ${n1}=    Set Variable    auth/v1/users/${user}
538     ${resp}    RequestsLibrary.Get    httpbin    ${n1}    headers=${HEADERS}
539     Should Be Equal As Strings    ${resp.status_code}    200
540     Should Contain    ${resp.content}    ${user}
541     [Return]    ${resp.content}
542
543 Get Users
544     [Documentation]    GET the complete set of users.
545     ${n1}=    Set Variable    auth/v1/users
546     ${resp}    RequestsLibrary.Get    httpbin    ${n1}    headers=${HEADERS}
547     Should Be Equal As Strings    ${resp.status_code}    200
548     Should Contain    ${resp.content}    ${user}
549     [Return]    ${resp.content}
550
551 Post New Domain
552     [Arguments]    ${domain}    ${data}
553     [Documentation]    Exercise REST command for domains POST command.
554     ${n1}=    Set Variable    auth/v1/domains
555     ${resp}    RequestsLibrary.Post    httpbin    ${n1}    headers=${HEADERS}    data=${data}
556     Should Be Equal As Strings    ${resp.status_code}    201
557     Should Contain    ${resp.content}    ${domain}
558     [Return]    ${resp.content}
559
560 Post New Role
561     [Arguments]    ${data}
562     [Documentation]    Use POST REST command to create specified Role.
563     ${n1}=    Set Variable    auth/v1/roles
564     ${resp}    RequestsLibrary.Post    httpbin    ${n1}    headers=${HEADERS}    data=${data}
565     #    HTTP/1.1 201 Created
566     Should Be Equal As Strings    ${resp.status_code}    201
567     [Return]    ${resp.content}
568
569 Post New User
570     [Arguments]    ${username}    ${data}
571     [Documentation]    Exercise REST command for users POST command.
572     ${n1}=    Set Variable    auth/v1/users
573     ${resp}    RequestsLibrary.Post    httpbin    ${n1}    headers=${HEADERS}    data=${data}
574     # grab the list of users, count the list, and then search the list for the specific user id
575     ${users}=    Get Users
576     ${depth}=    Nodecount    ${users}    users    userid
577     ${abc}=    Get User Id By Username    ${users}    ${username}    ${depth}
578     Should Be Equal As Strings    ${resp.status_code}    201
579     Should Contain    ${resp.content}    ${username}
580     [Return]    ${resp.content}
581
582 Get User By Name
583     [Arguments]    ${jsonblock}    ${property}
584     [Documentation]    hand this function a block of Json, and it will find your
585     ...    user by name and return userid
586     ${foundit}=    Get From Dictionary    ${jsonblock}    ${property}
587
588 Update Specific Domain
589     [Arguments]    ${data}    ${domainid}
590     [Documentation]    Update the specified domainid with a new name specified in domain-name
591     ${n1}=    Set Variable    auth/v1/domains/${domainid}
592     ${resp}    RequestsLibrary.Put    httpbin    ${n1}    headers=${HEADERS}    data=${data}
593     # Should Be Equal As Strings    ${resp.status_code}    201
594     Log    ${resp.content}
595
596 Update Specific Role
597     [Arguments]    ${data}    ${roleid}
598     [Documentation]    Update the specified roleid with a new information name specified
599     ${n1}=    Set Variable    auth/v1/roles/${roleid}
600     ${resp}    RequestsLibrary.Put    httpbin    ${n1}    headers=${HEADERS}    data=${data}
601     # Should Be Equal As Strings    ${resp.status_code}    201
602     Log    ${resp.content}
603
604 Update Specific User
605     [Arguments]    ${data}    ${userid}
606     [Documentation]    Update the specified userid with a new information name specified
607     ${n1}=    Set Variable    auth/v1/users/${userid}
608     ${resp}    RequestsLibrary.Put    httpbin    ${n1}    headers=${HEADERS}    data=${data}
609     # Should Be Equal As Strings    ${resp.status_code}    201
610     Log    ${resp.content}
611
612 Delete Domain
613     [Arguments]    ${domainid}
614     [Documentation]    Delete the specified domain, by id
615     ${n1}=    Set Variable    auth/v1/domains/${domainid}
616     Log    ${n1}
617     ${resp}    RequestsLibrary.Delete    httpbin    ${n1}    headers=${HEADERS}
618     Should Be Equal As Strings    ${resp.status_code}    204
619     Log    ${resp.content}
620
621 Delete User
622     [Arguments]    ${userid}
623     [Documentation]    Delete the specified user, by id
624     ${n1}=    Set Variable    auth/v1/users/${userid}
625     ${resp}    RequestsLibrary.Delete    httpbin    ${n1}    headers=${HEADERS}
626     Should Be Equal As Strings    ${resp.status_code}    204
627     Log    ${resp.content}
628
629 Delete Role
630     [Arguments]    ${roleid}
631     [Documentation]    Use DELETE REST command to wipe out a Role created for testing.
632     ${n1}=    Set Variable    auth/v1/roles/${roleid}
633     ${resp}    RequestsLibrary.Delete    httpbin    ${n1}    headers=${HEADERS}
634     Should Be Equal As Strings    ${resp.status_code}    204
635     #Should NOT Contain    ${resp.content}    ${roleid}
636     [Return]    ${resp.content}
637
638 Post Role To Domain And User
639     [Arguments]    ${data}    ${domainid}    ${userid}
640     [Documentation]    Exercise REST POST command for posting a role to particular domain and user
641     ${n1}=    Set Variable    auth/v1/domains/${domainid}/users/${userid}/roles
642     # now post it
643     ${resp}    RequestsLibrary.Post    httpbin    ${n1}    headers=${HEADERS}    data=${data}
644     Should Be Equal As Strings    ${resp.status_code}    201
645     [Return]    ${resp.content}
646
647 Get Roles For Specific Domain And User
648     [Arguments]    ${domainid}    ${userid}
649     [Documentation]    Exercise REST GET command for roles in a specific domain and user
650     ${n1}=    Set Variable    auth/v1/domains/${domainid}/users/${userid}/roles
651     # now get it
652     ${resp}    RequestsLibrary.Get    httpbin    ${n1}    headers=${HEADERS}
653     Should Be Equal As Strings    ${resp.status_code}    200
654     [Return]    ${resp.content}
655
656 Delete Specific Grant
657     [Arguments]    ${domainid}    ${userid}    ${roleid}
658     [Documentation]    Exercise REST DELETE command for a grant by roleid
659     ${n1}=    Set Variable    auth/v1/domains/${domainid}/users/${userid}/roles/${roleid}
660     # now delete it
661     ${resp}    RequestsLibrary.Delete    httpbin    ${n1}    headers=${HEADERS}
662     Should Be Equal As Strings    ${resp.status_code}    204
663     [Return]    ${resp.content}
664
665 Parse Item From Blob By Offset
666     [Arguments]    ${item}    ${offset}
667     [Documentation]    Parse out a field from JSON structure
668     ${x}=    Split String    ${item}    ,
669     ${y}=    Get From List    ${x}    ${offset}
670     ${z}=    Split String    ${y}    :
671     # offset is one in next line because you are looking at a key:value pair
672     ${return_item_}=    Get From List    ${z}    1
673     ${return_item}=    Replace String    ${return_item_}    "    ${EMPTY}
674     [Return]    ${return_item}
675
676 Create Random Name
677     [Arguments]    ${basename}
678     [Documentation]    Take the basename given and return a new name with date-time-stamp appended.
679     ${datetime}=    Get Current Date    result_format=%Y-%m-%d-%H-%M
680     Log    ${datetime}
681     ${newname}=    Catenate    SEPARATOR=-    ${basename}    ${datetime}
682     [Return]    ${newname}
683
684 Pop Name Off Json
685     [Arguments]    ${jsonstring}
686     [Documentation]    Pop the name item out of the Json string
687     # split it up to get the id
688     ${x}=    Split String    ${jsonstring}    ,
689     ${y}=    Get From List    ${x}    1
690     ${z}=    Split String    ${y}    :
691     ${name}=    Get From List    ${z}    1
692     ${name}=    Replace String    ${name}    "    ${EMPTY}
693     Log    ${name}
694     [Return]    ${name}
695
696 Verify Contents
697     [Arguments]    ${content_block}    ${keyvar}
698     [Documentation]    Verify that the content block passed in, contains the variable identified in second argument
699     Should Contain    ${content_block}    ${keyvar}
700
701 Rough Clean
702     [Documentation]    Clean up domains, users, roles in db, keep original 4 of each
703     ${domains}=    Get Domains
704     ${roles}=    Get Roles
705     ${users}=    Get Users
706     ${domcount}=    Nodecount    ${domains}    domains    "domainid"
707     ${rolecount}=    Nodecount    ${roles}    roles    "roleid"
708     ${usercount}=    Nodecount    ${users}    users    "userid"
709     : FOR    ${index}    IN RANGE    5    ${domains}
710     \    Delete Domain    ${index}
711     : FOR    ${index}    IN RANGE    5    ${roles}
712     \    Delete Role    ${index}
713     : FOR    ${index}    IN RANGE    5    ${users}
714     \    Delete User    ${index}