2 Library ./RequestsLibrary.py
3 Variables ../variables/Variables.py
6 ${WORKSPACE} /opt/jenkins-integration/workspace/shared-controller
7 ${BUNDLEFOLDER} distribution-karaf-0.3.0-SNAPSHOT
8 ${AUTHN_CFG_FILE} ${WORKSPACE}/${BUNDLEFOLDER}/etc/org.opendaylight.aaa.authn.cfg
12 [Arguments] ${controller_ip} ${auth_data}
13 [Documentation] Makes a POST REST call to the AUTH_TOKEN_API with the given auth_data and returns the response
14 Create Session ODL_SESSION http://${controller_ip}:8181
15 ${headers}= Create Dictionary Content-Type application/x-www-form-urlencoded
16 ${resp}= RequestsLibrary.POST ODL_SESSION ${AUTH_TOKEN_API} data=${auth_data} headers=${headers}
21 [Arguments] ${user}=${USER} ${password}=${PWD} ${scope}=${SCOPE} ${client_id}=${EMPTY} ${client_secret}=${EMPTY}
22 [Documentation] returns a string in the direct authentacation format (e.g., grant_type=password&username=admin&password=admin).
23 ... It can also be passed scope, client_id and client_secret arguments for the case of client specific authorization
24 ${data}= Set Variable grant_type=password&username=${user}&password=${password}&scope=${scope}
25 ${data}= Run Keyword If "${client_id}" != "${EMPTY}" Set Variable ${data}&client_id=${client_id} ELSE Set Variable
27 ${data}= Run Keyword If "${client_secret}" != "${EMPTY}" Set Variable ${data}&client_secret=${client_secret} ELSE Set Variable
31 Disable Authentication On Controller
32 [Arguments] ${controller_ip}
33 [Documentation] Will disable token based authentication. Currently, that is done with a config file change
34 SSHLibrary.Open Connection ${controller_ip}
35 Login With Public Key ${MININET_USER} ${USER_HOME}/.ssh/id_rsa any
36 ${cmd}= Set Variable sed -i 's/^authEnabled=.*$/authEnabled=false/g' ${AUTHN_CFG_FILE}
37 SSHLibrary.Execute Command ${cmd}
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 ${MININET_USER} ${USER_HOME}/.ssh/id_rsa any
44 ${cmd}= Set Variable sed -i 's/^authEnabled=.*$/authEnabled=true/g' ${AUTHN_CFG_FILE}
45 SSHLibrary.Execute Command ${cmd}
48 [Arguments] ${user}=${USER} ${password}=${PWD} ${scope}=${SCOPE} ${client_id}=${EMPTY} ${client_secret}=${EMPTY}
49 [Documentation] Wrapper used to login to controller and retrieve an auth token. Optional argumented available for client based credentials.
50 ${auth_data}= Create Auth Data ${USER} ${PWD} ${scope} ${client_id} ${client_secret}
51 ${resp}= AAA Login ${CONTROLLER} ${auth_data}
52 Should Be Equal As Strings ${resp.status_code} 201
53 ${auth_token}= Extract Value From Content ${resp.content} /access_token strip
54 [Return] ${auth_token}
58 [Documentation] Requests the given token be revoked via POST to ${REVOKE_TOKEN_API}
59 ${headers}= Create Dictionary Content-Type application/x-www-form-urlencoded
60 ${resp}= RequestsLibrary.POST ODL_SESSION ${REVOKE_TOKEN_API} data=${token} headers=${headers}
61 Should Be Equal As Strings ${resp.status_code} 204
65 [Documentation] Validates the given string is in the proper "token" format
66 Should Match Regexp ${token} [0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}