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