Clean up new AAA auth suite
[integration/test.git] / csit / suites / aaa / authn / Restconf_Basic_Auth.robot
1 #
2 # Copyright (c) Lumina Networks 2020 and others.
3 # All rights reserved.
4 #
5 # This program and the accompanying materials are made available under the
6 # terms of the Eclipse Public License v1.0 which accompanies this distribution,
7 # and is available at http://www.eclipse.org/legal/epl-v10.html
8 #
9
10 *** Settings ***
11 Documentation     Test Basic Authentication support in RESTCONF
12 Suite Teardown    Delete All Sessions
13 Library           RequestsLibrary
14 Library           String
15 Resource          ../../../variables/Variables.robot
16
17 *** Variables ***
18 ${ADMIN_USER}     ${ODL_RESTCONF_USER}
19 ${ADMIN_PW}       ${ODL_RESTCONF_PASSWORD}
20 ${RESTCONF_TEST_URL}    ${MODULES_API}
21 ${JOLOKIA_TEST_URL}    jolokia
22 ${JOLOKIA_USER}    ${ODL_RESTCONF_USER}
23 ${JOLOKIA_PW}     ${ODL_RESTCONF_PASSWORD}
24 ${BAD_USER}       bad_user
25 ${BAD_PW}         bad_pw
26 ${JOLOKIA_BAD_USER}    ${BAD_USER}
27 ${USERS_REST_URL}    auth/v1/users
28 ${USER_USER}      user
29 ${USER_PW}        user
30
31 *** Test Cases ***
32 No RESTCONF Credentials
33     [Documentation]    Given no credentials GET RESTCONF fails
34     Auth Should Fail    ${RESTCONF_TEST_URL}    ${EMPTY}    ${EMPTY}
35
36 Incorrect RESTCONF Password
37     [Documentation]    Given incorrect password GET RESTCONF fails
38     Auth Should Fail    ${RESTCONF_TEST_URL}    ${ADMIN_USER}    ${BAD_PW}
39
40 Incorrect RESTCONF Username
41     [Documentation]    Given incorrect username GET RESTCONF fails
42     Auth Should Fail    ${RESTCONF_TEST_URL}    ${BAD_USER}    ${ADMIN_PW}
43
44 Correct RESTCONF Credentials
45     [Documentation]    Given correct credentials GET RESTCONF succeeds
46     Auth Should Pass    ${RESTCONF_TEST_URL}    ${ADMIN_USER}    ${ADMIN_PW}
47
48 No Jolokia REST Credentials
49     [Documentation]    Given no credentials, HTTP GET on a Jolokia endpoint fails
50     Auth Should Fail    ${JOLOKIA_TEST_URL}    ${EMPTY}    ${EMPTY}
51
52 Incorrect Jolokia REST Password
53     [Documentation]    Given incorrect password, GET on a Jolokia endpoint fails
54     Auth Should Fail    ${JOLOKIA_TEST_URL}    ${JOLOKIA_USER}    ${BAD_PW}
55
56 Incorrect Jolokia REST Username
57     [Documentation]    Given incorrect username, GET on a Jolokia endpoint fails
58     Auth Should Fail    ${JOLOKIA_TEST_URL}    ${JOLOKIA_BAD_USER}    ${JOLOKIA_PW}
59
60 Correct Jolokia REST Credentials
61     [Documentation]    Given correct credentials, GET on a Jolokia endpoint succeeds
62     Auth Should Pass    ${JOLOKIA_TEST_URL}    ${JOLOKIA_USER}    ${JOLOKIA_PW}
63
64 IDM Endpoints Only Available To admin Role
65     [Documentation]    A user with a non-"admin" role should not have access to AAA endpoints
66     ${auth}    Create List    ${USER_USER}    ${USER_PW}
67     Create Session    httpbin    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${auth}    headers=${HEADERS}
68     ${resp} =    RequestsLibrary.Get Request    httpbin    ${USERS_REST_URL}
69     Should Be Equal As Numbers    ${resp.status_code}    401
70
71 *** Keywords ***
72 Auth Should Fail
73     [Arguments]    ${url}    ${user}    ${password}
74     [Documentation]    Checks the given HTTP RESTCONF response for authentication failure
75     @{auth} =    Create List    ${user}    ${password}
76     Create Session    httpbin    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${auth}    headers=${HEADERS}
77     ${resp} =    RequestsLibrary.Get Request    httpbin    ${url}
78     Should Be Equal As Strings    ${resp.status_code}    401
79     ${header_value} =    Convert To Uppercase    ${resp.headers}[www-authenticate]
80     Should Contain    ${header_value}    BASIC
81     Log    ${resp.content}
82
83 Auth Should Pass
84     [Arguments]    ${url}    ${user}    ${password}
85     [Documentation]    Checks the given HTTP RESTCONF response for authentication failure
86     @{auth} =    Create List    ${user}    ${password}
87     Create Session    httpbin    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${auth}    headers=${HEADERS}
88     ${resp} =    RequestsLibrary.Get Request    httpbin    ${url}
89     Should Be Equal As Strings    ${resp.status_code}    200