From 7c8729021b059da44013798a9e07f89cad8ea80e Mon Sep 17 00:00:00 2001 From: Frederico Sequeira <frederico.sequeira@ext.ec.europa.eu> Date: Tue, 4 Mar 2025 16:11:36 +0000 Subject: [PATCH 1/3] =?UTF-8?q?=E2=9C=A8=20Add=20redirect=20changes=20to?= =?UTF-8?q?=20RPS=20plugin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 977ec0b..b5e01ce 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,7 +5,7 @@ netbox-docker-plugin == 1.* --extra-index-url https://code.europa.eu/api/v4/projects/662/packages/pypi/simple netbox-cert-plugin == 0.3.* --extra-index-url https://code.europa.eu/api/v4/projects/623/packages/pypi/simple -netbox-rps-plugin == 0.25.* +netbox-rps-plugin == 0.26.* supervisor == 4.2.5 netbox-mac-address-plugin == 1.0.* --extra-index-url https://code.europa.eu/api/v4/projects/921/packages/pypi/simple -- GitLab From d2b138803cdc47765544d77ed6a5c44063a6f964 Mon Sep 17 00:00:00 2001 From: Frederico Sequeira <frederico.sequeira@ext.ec.europa.eu> Date: Mon, 10 Mar 2025 16:37:24 +0000 Subject: [PATCH 2/3] =?UTF-8?q?=E2=9C=85=20Add=20Mapping=20redirect=20robo?= =?UTF-8?q?t=20testing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/robot/netbox_rps_plugin/redirect.robot | 97 ++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 tests/robot/netbox_rps_plugin/redirect.robot diff --git a/tests/robot/netbox_rps_plugin/redirect.robot b/tests/robot/netbox_rps_plugin/redirect.robot new file mode 100644 index 0000000..d3b268f --- /dev/null +++ b/tests/robot/netbox_rps_plugin/redirect.robot @@ -0,0 +1,97 @@ +*** Settings *** +Test Tags mac +Library RequestsLibrary +Library OperatingSystem +Library Collections +Variables ../variables.yaml + +*** Variables *** +${BASE_URL} http://${HOST}:${PORT} +${MAPPING_ENDPOINT} /api/plugins/rps/mapping/ +${REDIRECT_ENDPOINT} /api/plugins/rps/redirect/ +${TOKEN} Token ${API_TOKEN} + +*** Test Cases *** + +Create Mapping for testing + ${HEADERS} Create Dictionary Content-Type ${CONTENT_TYPE} Authorization ${TOKEN} + ${payload} Create Dictionary source http://testsource.com target http://testtarget.com + ${response}= POST ${BASE_URL}${MAPPING_ENDPOINT} json=${payload} headers=${HEADERS} expected_status=201 + ${json} Set Variable ${response.json()} + Convert to Dictionary ${json} + ${MAPPING_ID} Get From Dictionary ${json} id + Set Global Variable ${MAPPING_ID} + +Create Valid Mapping Redirect + ${HEADERS} Create Dictionary Content-Type ${CONTENT_TYPE} Authorization ${TOKEN} + ${NOW}= get time + ${payload} Create Dictionary source http://testsource.com/A target http://testtarget.com/B mapping ${MAPPING_ID} redirect_type 1-1 activation_date ${NOW} + ${response}= POST ${BASE_URL}${REDIRECT_ENDPOINT} json=${payload} headers=${HEADERS} expected_status=201 + ${json} Set Variable ${response.json()} + Convert to Dictionary ${json} + ${REDIRECT_ID} Get From Dictionary ${json} id + Set Global Variable ${REDIRECT_ID} + +Create 2nd Valid Mapping Redirect + ${HEADERS} Create Dictionary Content-Type ${CONTENT_TYPE} Authorization ${TOKEN} + ${NOW}= get time + ${payload} Create Dictionary source http://testsource.com/Z target http://testtarget.com/B mapping ${MAPPING_ID} redirect_type 1-1 activation_date ${NOW} deactivation_date 2999-01-01T15:53:01.622818Z + ${response}= POST ${BASE_URL}${REDIRECT_ENDPOINT} json=${payload} headers=${HEADERS} expected_status=201 + ${json} Set Variable ${response.json()} + Convert to Dictionary ${json} + ${REDIRECT_ID} Get From Dictionary ${json} id + Set Global Variable ${REDIRECT_ID} + +Create Duplicaded Redirect + ${HEADERS} Create Dictionary Content-Type ${CONTENT_TYPE} Authorization ${TOKEN} + ${NOW}= get time + ${payload} Create Dictionary source http://testsource.com/A target http://testtarget.com/B mapping ${MAPPING_ID} redirect_type 1-1 activation_date ${NOW} + ${response}= POST ${BASE_URL}${REDIRECT_ENDPOINT} json=${payload} headers=${HEADERS} expected_status=400 + +Create Incomplete Redirect- Missing Source + ${HEADERS} Create Dictionary Content-Type ${CONTENT_TYPE} Authorization ${TOKEN} + ${NOW}= get time + ${payload} Create Dictionary target http://testtarget.com/B mapping ${MAPPING_ID} redirect_type 1-1 activation_date ${NOW} + ${response}= POST ${BASE_URL}${REDIRECT_ENDPOINT} json=${payload} headers=${HEADERS} expected_status=400 + +Create Incomplete Redirect- Missing Target + ${HEADERS} Create Dictionary Content-Type ${CONTENT_TYPE} Authorization ${TOKEN} + ${NOW}= get time + ${payload} Create Dictionary source http://testsource.com/C mapping ${MAPPING_ID} redirect_type 1-1 activation_date ${NOW} + ${response}= POST ${BASE_URL}${REDIRECT_ENDPOINT} json=${payload} headers=${HEADERS} expected_status=400 + +Create Incomplete Redirect- Missing Mapping + ${HEADERS} Create Dictionary Content-Type ${CONTENT_TYPE} Authorization ${TOKEN} + ${NOW}= get time + ${payload} Create Dictionary source http://testsource.com/C target http://testtarget.com/B redirect_type 1-1 activation_date ${NOW} + ${response}= POST ${BASE_URL}${REDIRECT_ENDPOINT} json=${payload} headers=${HEADERS} expected_status=400 + +Create Incomplete Redirect- Check Date Default + ${HEADERS} Create Dictionary Content-Type ${CONTENT_TYPE} Authorization ${TOKEN} + ${NOW}= get time + ${payload} Create Dictionary source http://testsource.com/datedefault target http://testtarget.com/B mapping ${MAPPING_ID} redirect_type 1-1 + ${response}= POST ${BASE_URL}${REDIRECT_ENDPOINT} json=${payload} headers=${HEADERS} expected_status=201 + +Create Incomplete Redirect- Check Type Default + ${HEADERS} Create Dictionary Content-Type ${CONTENT_TYPE} Authorization ${TOKEN} + ${NOW}= get time + ${payload} Create Dictionary source http://testsource.com/typedefault target http://testtarget.com/B mapping ${MAPPING_ID} activation_date ${NOW} + ${response}= POST ${BASE_URL}${REDIRECT_ENDPOINT} json=${payload} headers=${HEADERS} expected_status=201 + +Create Invalid (Not the same source) Redirect + ${HEADERS} Create Dictionary Content-Type ${CONTENT_TYPE} Authorization ${TOKEN} + ${NOW}= get time + ${payload} Create Dictionary source http://testsource_wrong.com/A target http://testtarget.com/B mapping ${MAPPING_ID} redirect_type 1-1 activation_date ${NOW} + ${response}= POST ${BASE_URL}${REDIRECT_ENDPOINT} json=${payload} headers=${HEADERS} expected_status=400 + +Create Overlaped Dates Redirect + ${HEADERS} Create Dictionary Content-Type ${CONTENT_TYPE} Authorization ${TOKEN} + ${NOW}= get time + ${payload} Create Dictionary source http://testsource.com/Z target http://testtarget.com/B mapping ${MAPPING_ID} redirect_type 1-1 activation_date ${NOW} deactivation_date 2500-01-01T15:53:01.622818Z + ${response}= POST ${BASE_URL}${REDIRECT_ENDPOINT} json=${payload} headers=${HEADERS} expected_status=400 + + +# Clean up +Delete Mac Address assigned to VLAN + ${HEADERS} Create Dictionary Content-Type ${CONTENT_TYPE} Authorization ${TOKEN} + ${response}= DELETE ${BASE_URL}${MAPPING_ENDPOINT}${MAPPING_ID} headers=${HEADERS} expected_status=204 -- GitLab From a0153dd50bf5cc674c2e60a0869bbff844be591a Mon Sep 17 00:00:00 2001 From: Frederico Sequeira <frederico.sequeira@ext.ec.europa.eu> Date: Tue, 11 Mar 2025 12:29:54 +0000 Subject: [PATCH 3/3] =?UTF-8?q?=E2=9C=85=20Add=20more=20detail=20to=20test?= =?UTF-8?q?s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/robot/netbox_rps_plugin/redirect.robot | 37 +++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/tests/robot/netbox_rps_plugin/redirect.robot b/tests/robot/netbox_rps_plugin/redirect.robot index d3b268f..245495c 100644 --- a/tests/robot/netbox_rps_plugin/redirect.robot +++ b/tests/robot/netbox_rps_plugin/redirect.robot @@ -3,6 +3,7 @@ Test Tags mac Library RequestsLibrary Library OperatingSystem Library Collections +Library DateTime Variables ../variables.yaml *** Variables *** @@ -47,51 +48,85 @@ Create Duplicaded Redirect ${NOW}= get time ${payload} Create Dictionary source http://testsource.com/A target http://testtarget.com/B mapping ${MAPPING_ID} redirect_type 1-1 activation_date ${NOW} ${response}= POST ${BASE_URL}${REDIRECT_ENDPOINT} json=${payload} headers=${HEADERS} expected_status=400 + ${json} Set Variable ${response.json()} + Convert to Dictionary ${json} + ${ERROR} Get From Dictionary ${json} source + Should Contain ${ERROR} A Redirect with the same source and overlapping timespan already exists. Create Incomplete Redirect- Missing Source ${HEADERS} Create Dictionary Content-Type ${CONTENT_TYPE} Authorization ${TOKEN} ${NOW}= get time ${payload} Create Dictionary target http://testtarget.com/B mapping ${MAPPING_ID} redirect_type 1-1 activation_date ${NOW} ${response}= POST ${BASE_URL}${REDIRECT_ENDPOINT} json=${payload} headers=${HEADERS} expected_status=400 + ${json} Set Variable ${response.json()} + Convert to Dictionary ${json} + ${ERROR} Get From Dictionary ${json} source + Should Contain ${ERROR} This field is required. Create Incomplete Redirect- Missing Target ${HEADERS} Create Dictionary Content-Type ${CONTENT_TYPE} Authorization ${TOKEN} ${NOW}= get time ${payload} Create Dictionary source http://testsource.com/C mapping ${MAPPING_ID} redirect_type 1-1 activation_date ${NOW} ${response}= POST ${BASE_URL}${REDIRECT_ENDPOINT} json=${payload} headers=${HEADERS} expected_status=400 + ${json} Set Variable ${response.json()} + Convert to Dictionary ${json} + ${ERROR} Get From Dictionary ${json} target + Should Contain ${ERROR} This field is required. Create Incomplete Redirect- Missing Mapping ${HEADERS} Create Dictionary Content-Type ${CONTENT_TYPE} Authorization ${TOKEN} ${NOW}= get time ${payload} Create Dictionary source http://testsource.com/C target http://testtarget.com/B redirect_type 1-1 activation_date ${NOW} ${response}= POST ${BASE_URL}${REDIRECT_ENDPOINT} json=${payload} headers=${HEADERS} expected_status=400 + ${json} Set Variable ${response.json()} + Convert to Dictionary ${json} + ${ERROR} Get From Dictionary ${json} mapping + Should Contain ${ERROR} This field is required. Create Incomplete Redirect- Check Date Default ${HEADERS} Create Dictionary Content-Type ${CONTENT_TYPE} Authorization ${TOKEN} ${NOW}= get time ${payload} Create Dictionary source http://testsource.com/datedefault target http://testtarget.com/B mapping ${MAPPING_ID} redirect_type 1-1 ${response}= POST ${BASE_URL}${REDIRECT_ENDPOINT} json=${payload} headers=${HEADERS} expected_status=201 + ${json} Set Variable ${response.json()} + Convert to Dictionary ${json} + ${DATE_DEFAULT} Get From Dictionary ${json} activation_date + ${CONVERTED_DATE_DEFAULT} Convert Date ${DATE_DEFAULT} result_format=%d %b %Y %I:%M %p + ${CONVERTED_NOW} Convert Date ${NOW} result_format=%d %b %Y %I:%M %p + Should Be Equal As Strings ${CONVERTED_DATE_DEFAULT} ${CONVERTED_NOW} Create Incomplete Redirect- Check Type Default ${HEADERS} Create Dictionary Content-Type ${CONTENT_TYPE} Authorization ${TOKEN} ${NOW}= get time ${payload} Create Dictionary source http://testsource.com/typedefault target http://testtarget.com/B mapping ${MAPPING_ID} activation_date ${NOW} ${response}= POST ${BASE_URL}${REDIRECT_ENDPOINT} json=${payload} headers=${HEADERS} expected_status=201 + ${json} Set Variable ${response.json()} + Convert to Dictionary ${json} + ${TYPE_DEFAULT} Get From Dictionary ${json} redirect_type + Should Be Equal As Strings ${TYPE_DEFAULT} 1-1 Create Invalid (Not the same source) Redirect ${HEADERS} Create Dictionary Content-Type ${CONTENT_TYPE} Authorization ${TOKEN} ${NOW}= get time ${payload} Create Dictionary source http://testsource_wrong.com/A target http://testtarget.com/B mapping ${MAPPING_ID} redirect_type 1-1 activation_date ${NOW} ${response}= POST ${BASE_URL}${REDIRECT_ENDPOINT} json=${payload} headers=${HEADERS} expected_status=400 + ${json} Set Variable ${response.json()} + Convert to Dictionary ${json} + ${ERROR} Get From Dictionary ${json} source + Should Contain ${ERROR} Redirect source must start with the mapping's source. Create Overlaped Dates Redirect ${HEADERS} Create Dictionary Content-Type ${CONTENT_TYPE} Authorization ${TOKEN} ${NOW}= get time ${payload} Create Dictionary source http://testsource.com/Z target http://testtarget.com/B mapping ${MAPPING_ID} redirect_type 1-1 activation_date ${NOW} deactivation_date 2500-01-01T15:53:01.622818Z ${response}= POST ${BASE_URL}${REDIRECT_ENDPOINT} json=${payload} headers=${HEADERS} expected_status=400 + ${json} Set Variable ${response.json()} + Convert to Dictionary ${json} + ${ERROR} Get From Dictionary ${json} source + Should Contain ${ERROR} A Redirect with the same source and overlapping timespan already exists. # Clean up -Delete Mac Address assigned to VLAN +Delete Mapping ${HEADERS} Create Dictionary Content-Type ${CONTENT_TYPE} Authorization ${TOKEN} ${response}= DELETE ${BASE_URL}${MAPPING_ENDPOINT}${MAPPING_ID} headers=${HEADERS} expected_status=204 -- GitLab