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