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