2 Library RequestsLibrary
3 Resource ../variables/Variables.robot
7 ${AUTHN_CFG_FILE} ${WORKSPACE}/${BUNDLEFOLDER}/etc/org.opendaylight.aaa.authn.cfg
11 [Arguments] ${controller_ip} ${auth_data}
12 [Documentation] Makes a POST REST call to the AUTH_TOKEN_API with the given auth_data and returns the response
13 Create Session ODL_SESSION http://${controller_ip}:8181
14 ${headers}= Create Dictionary Content-Type=application/x-www-form-urlencoded
15 ${resp}= RequestsLibrary.POST Request ODL_SESSION ${AUTH_TOKEN_API} data=${auth_data} headers=${headers}
20 [Arguments] ${user}=${USER} ${password}=${PWD} ${scope}=${SCOPE} ${client_id}=${EMPTY} ${client_secret}=${EMPTY}
21 [Documentation] returns a string in the direct authentacation format (e.g., grant_type=password&username=admin&password=admin).
22 ... It can also be passed scope, client_id and client_secret arguments for the case of client specific authorization
23 ${data}= Set Variable grant_type=password&username=${user}&password=${password}&scope=${scope}
24 ${data}= Run Keyword If "${client_id}" != "${EMPTY}" Set Variable ${data}&client_id=${client_id}
25 ... ELSE Set Variable ${data}
26 ${data}= Run Keyword If "${client_secret}" != "${EMPTY}" Set Variable ${data}&client_secret=${client_secret}
27 ... ELSE Set Variable ${data}
30 Disable Authentication On Controller
31 [Arguments] ${controller_ip}
32 [Documentation] Will disable token based authentication. Currently, that is done with a config file change
33 SSHLibrary.Open Connection ${controller_ip}
34 Login With Public Key ${ODL_SYSTEM_USER} ${USER_HOME}/.ssh/${SSH_KEY} any
35 ${cmd}= Set Variable sed -i 's/^authEnabled=.*$/authEnabled=false/g' ${AUTHN_CFG_FILE}
36 SSHLibrary.Execute Command ${cmd}
37 SSHLibrary.Close Connection
39 Enable Authentication On Controller
40 [Arguments] ${controller_ip}
41 [Documentation] Will enable token based authentication. Currently, that is done with a config file change
42 SSHLibrary.Open Connection ${controller_ip}
43 Login With Public Key ${ODL_SYSTEM_USER} ${USER_HOME}/.ssh/${SSH_KEY} any
44 ${cmd}= Set Variable sed -i 's/^authEnabled=.*$/authEnabled=true/g' ${AUTHN_CFG_FILE}
45 SSHLibrary.Execute Command ${cmd}
46 SSHLibrary.Close Connection
49 [Arguments] ${user}=${USER} ${password}=${PWD} ${scope}=${SCOPE} ${client_id}=${EMPTY} ${client_secret}=${EMPTY}
50 [Documentation] Wrapper used to login to controller and retrieve an auth token. Optional argumented available for client based credentials.
51 ${auth_data}= Create Auth Data ${USER} ${PWD} ${scope} ${client_id} ${client_secret}
52 ${resp}= AAA Login ${ODL_SYSTEM_IP} ${auth_data}
53 Should Be Equal As Strings ${resp.status_code} 201
54 ${auth_token}= Extract Value From Content ${resp.content} /access_token strip
55 [Return] ${auth_token}
59 [Documentation] Requests the given token be revoked via POST to ${REVOKE_TOKEN_API}
60 ${headers}= Create Dictionary Content-Type=application/x-www-form-urlencoded
61 ${resp}= RequestsLibrary.POST Request ODL_SESSION ${REVOKE_TOKEN_API} data=${token} headers=${headers}
62 Should Be Equal As Strings ${resp.status_code} 204
66 [Documentation] Validates the given string is in the proper "token" format
67 Should Match Regexp ${token} [0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}
70 [Arguments] ${user_id}=${EMPTY}
71 [Documentation] Will return user information. If no user id is passed, it will retrieve all users in DB
72 Create Session httpbin http://${ODL_SYSTEM_IP}:${RESTPORT}
73 ${headers}= Create Dictionary Content-Type=application/x-www-form-urlencoded
74 ${resp}= RequestsLibrary.GET Request httpbin ${idmurl}/users/${user_id} headers=${headers}
75 Should Be Equal As Strings ${resp.status_code} 200
80 [Arguments] ${user_data}
81 [Documentation] Will return user information. If no user id is passed, it will retrieve all users in DB
82 Create Session httpbin http://${ODL_SYSTEM_IP}:${RESTPORT}
83 ${headers}= Create Dictionary Content-Type=application/json
84 ${resp}= RequestsLibrary.POST Request httpbin ${idmurl}/users headers=${headers} data=${user_data}
85 Should Be Equal As Strings ${resp.status_code} 201