Add new restconf auth suite
[integration/test.git] / csit / suites / aaa / authn / 010_Credential_Authentication.robot
1 *** Settings ***
2 Documentation     AAA System Tests
3 Suite Setup       SetupUtils.Setup_Utils_For_Setup_And_Teardown
4 Suite Teardown    Delete All Sessions
5 Test Setup        SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
6 Library           Collections
7 Library           HttpLibrary.HTTP
8 Library           OperatingSystem
9 Library           RequestsLibrary
10 Library           String
11 Library           ../../../libraries/Common.py
12 Resource          ../../../libraries/AAAKeywords.robot
13 Resource          ../../../libraries/KarafKeywords.robot
14 Resource          ../../../libraries/SetupUtils.robot
15 Resource          ../../../libraries/Utils.robot
16 Resource          ../../../variables/Variables.robot
17
18 *** Variables ***
19
20 *** Test Cases ***
21 Get Token With Valid Username And Password
22     [Documentation]    Sanity test to ensure default user/password can get a token
23     ${auth_token}=    Get Auth Token
24     Should Be String    ${auth_token}
25     Log    Token: ${auth_token}
26     Validate Token Format    ${auth_token}
27
28 Fail To Get Token With Invalid Username And Password
29     [Documentation]    Negative test to verify invalid user/password is denied a token
30     ${bad_user}=    Set Variable    notTheAdmin
31     ${auth_data}=    Create Auth Data    ${bad_user}    notTheAdminPassword
32     ${resp}=    AAA Login    ${ODL_SYSTEM_IP}    ${auth_data}
33     Should Be Equal As Strings    ${resp.status_code}    401
34     Log    ${resp.content}
35     ${error_msg}=    Extract Value From Content    ${resp.content}    /error    strip
36     Should Contain    ${error_msg}    User :${bad_user} does not exist
37
38 Create Token with Client Authorization
39     [Documentation]    Get a token using client domain
40     ${auth_token}=    Get Auth Token    ${USER}    ${PWD}    ${SCOPE}    dlux    secrete
41     Should Be String    ${auth_token}
42     Log    Token: ${auth_token}
43     Validate Token Format    ${auth_token}
44
45 Token Authentication In REST Request
46     [Documentation]    Use a token to make a successful REST transaction
47     ${auth_token}=    Get Token And Verify
48     [Teardown]    Report_Failure_Due_To_Bug    AAA-101
49
50 Revoke Token And Verify Transaction Fails
51     [Documentation]    negative test to revoke valid token and check that REST transaction fails
52     ${auth_token}=    Wait Until Keyword Succeeds    10s    1s    Get Token and Verify
53     Revoke Auth Token    ${auth_token}
54     Make REST Transaction    401    ${auth_token}
55
56 Disable Authentication And Re-Enable Authentication
57     [Documentation]    Toggles authentication off and verifies that no login credentials are needed for REST transactions.
58     ...    Test has been disabled due to the fact that this interface has changed. Authentication is now disabled
59     ...    through modification of shiro.ini, which requires controller restart and is not suit for this test.
60     [Tags]    exclude
61     Disable Authentication On Controller    ${ODL_SYSTEM_IP}
62     Wait Until Keyword Succeeds    10s    1s    Make REST Transaction    200
63     Enable Authentication On Controller    ${ODL_SYSTEM_IP}
64     Wait Until Keyword Succeeds    10s    1s    Validate That Authentication Fails With Wrong Token
65     ${auth_token}=    Get Token And Verify
66     [Teardown]    Report_Failure_Due_To_Bug    4922
67
68 *** Keywords ***
69 Get Token And Verify
70     ${auth_token}=    Get Auth Token
71     Make REST Transaction    200    ${auth_token}
72     [Return]    ${auth_token}
73
74 Validate That Authentication Fails With Wrong Token
75     ${bad_token}=    Set Variable    notARealToken
76     Make REST Transaction    401    ${bad_token}
77
78 Make REST Transaction
79     [Arguments]    ${expected_status_code}    ${auth_data}=${EMPTY}
80     Create Session    ODL_SESSION    http://${ODL_SYSTEM_IP}:8181
81     ${headers}=    Create Dictionary    Content-Type=application/x-www-form-urlencoded
82     Run Keyword If    "${auth_data}" != "${EMPTY}"    Set To Dictionary    ${headers}    Authorization    Bearer ${auth_data}
83     ${resp}=    RequestsLibrary.GET Request    ODL_SESSION    ${MODULES_API}    headers=${headers}
84     Log    STATUS_CODE: ${resp.status_code} CONTENT: ${resp.content}
85     Should Be Equal As Strings    ${resp.status_code}    ${expected_status_code}