b943838d462c13c101a37290f980468328366b44
[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 ${RESTCONF_TEST_URL}    ${MODULES_API}
19 ${JOLOKIA_TEST_URL}    jolokia
20 ${JOLOKIA_USER}    ${ODL_RESTCONF_USER}
21 ${JOLOKIA_PW}     ${ODL_RESTCONF_PASSWORD}
22 ${JOLOKIA_BAD_USER}    bad_user
23 ${BAD_PW}         bad_pw
24 ${USERS_REST_URL}    auth/v1/users
25 ${USER_USER}      user
26 ${USER_PW}        user
27
28 *** Test Cases ***
29 No RESTCONF Credentials
30     [Documentation]    Given no credentials GET RESTCONF fails
31     Auth Should Fail    ${RESTCONF_TEST_URL}    ${EMPTY}    ${EMPTY}
32
33 Incorrect RESTCONF Password
34     [Documentation]    Given incorrect password GET RESTCONF fails
35     Auth Should Fail    ${RESTCONF_TEST_URL}    some_user    ${ODL_RESTCONF_PASSWORD}
36
37 Incorrect RESTCONF Username
38     [Documentation]    Given incorrect username GET RESTCONF fails
39     Auth Should Fail    ${RESTCONF_TEST_URL}    ${ODL_RESTCONF_USER}    ${BAD_PW}
40
41 Correct RESTCONF Credentials
42     [Documentation]    Given correct credentials GET RESTCONF succeeds
43     Auth Should Pass    ${RESTCONF_TEST_URL}    ${ODL_RESTCONF_USER}    ${ODL_RESTCONF_PASSWORD}
44
45 No Jolokia REST Credentials
46     [Documentation]    Given no credentials, HTTP GET on a Jolokia endpoint fails
47     Auth Should Fail    ${JOLOKIA_TEST_URL}    ${EMPTY}    ${EMPTY}
48
49 Incorrect Jolokia REST Password
50     [Documentation]    Given incorrect password, GET on a Jolokia endpoint fails
51     Auth Should Fail    ${JOLOKIA_TEST_URL}    ${JOLOKIA_USER}    ${BAD_PW}
52
53 Incorrect Jolokia REST Username
54     [Documentation]    Given incorrect username, GET on a Jolokia endpoint fails
55     Auth Should Fail    ${JOLOKIA_TEST_URL}    ${JOLOKIA_BAD_USER}    ${JOLOKIA_PW}
56
57 Correct Jolokia REST Credentials
58     [Documentation]    Given correct credentials, GET on a Jolokia endpoint succeeds
59     Auth Should Pass    ${JOLOKIA_TEST_URL}    ${JOLOKIA_USER}    ${JOLOKIA_PW}
60
61 IDM Endpoints Only Available To admin Role
62     [Documentation]    A user with a non-"admin" role should not have access to AAA endpoints
63     ${auth}    Create List    ${USER_USER}    ${USER_PW}
64     Create Session    httpbin    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${auth}    headers=${HEADERS}
65     ${resp} =    RequestsLibrary.Get Request    httpbin    ${USERS_REST_URL}
66     Should Be Equal As Numbers    ${resp.status_code}    401
67
68 *** Keywords ***
69 Auth Should Fail
70     [Arguments]    ${url}    ${user}    ${password}
71     [Documentation]    Checks the given HTTP RESTCONF response for authentication failure
72     @{auth} =    Create List    ${user}    ${password}
73     Create Session    httpbin    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${auth}    headers=${HEADERS}
74     ${resp} =    RequestsLibrary.Get Request    httpbin    ${url}
75     Should Be Equal As Strings    ${resp.status_code}    401
76     ${header_value} =    Convert To Uppercase    ${resp.headers}[www-authenticate]
77     Should Contain    ${header_value}    BASIC
78     Log    ${resp.content}
79
80 Auth Should Pass
81     [Arguments]    ${url}    ${user}    ${password}
82     [Documentation]    Checks the given HTTP RESTCONF response for authentication failure
83     @{auth} =    Create List    ${user}    ${password}
84     Create Session    httpbin    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${auth}    headers=${HEADERS}
85     ${resp} =    RequestsLibrary.Get Request    httpbin    ${url}
86     Should Be Equal As Strings    ${resp.status_code}    200