diff --git a/.github/workflows/compose/docker-compose.yml b/.github/workflows/compose/docker-compose.yml index 601c6b8cab..c6aed16f6f 100644 --- a/.github/workflows/compose/docker-compose.yml +++ b/.github/workflows/compose/docker-compose.yml @@ -50,6 +50,7 @@ services: working_dir: /tests volumes: - ../tests:/tests + - /var/run/docker.sock:/var/run/docker.sock environment: - KNOX_GATEWAY_URL=https://knox:8443/ command: > diff --git a/.github/workflows/tests/requirements.txt b/.github/workflows/tests/requirements.txt index 9967c535d4..8ef8698ae1 100644 --- a/.github/workflows/tests/requirements.txt +++ b/.github/workflows/tests/requirements.txt @@ -1,2 +1,3 @@ -requests==2.32.4 +docker==7.1.0 pytest==8.3.4 +requests==2.32.4 diff --git a/.github/workflows/tests/test_knox_cli.py b/.github/workflows/tests/test_knox_cli.py new file mode 100644 index 0000000000..b4d9f16ffe --- /dev/null +++ b/.github/workflows/tests/test_knox_cli.py @@ -0,0 +1,44 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to you under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import unittest +from util.knox import Knox + +class TestKnoxCLI(unittest.TestCase): + def setUp(self): + self.knox = Knox("compose-knox-1") + self.knox_cli_path = "/knox-runtime/bin/knoxcli.sh" + + def test_knox_cli_create_list_aliases(self): + """ + Validating creating and listing of aliases for multiple cluster + + Step: + - Execute: + knoxcli.sh create-list-aliases --alias aliasx1 --value value --alias aliasx2 --value value --cluster clusterX + --alias aliasy1 --value value --alias aliasy2 --value value --cluster clusterY + + Result: + all Alias in the clusters should be created and listed + :return: + """ + print(f"\nTesting create-list-aliases command") + cmd = ("{} create-list-aliases --alias aliasx1 --value value --alias aliasx2 --value value --cluster clusterX" + " --alias aliasy1 --value value --alias aliasy2 --value value --cluster clusterY").format(self.knox_cli_path) + cmd_output = self.knox.run_knox_cmd(cmd) + self.assertIn("Listing aliases for: clusterX", cmd_output) + self.assertIn("Listing aliases for: clusterY", cmd_output) + self.assertIn("2 alias(es) have been successfully created: [aliasx1, aliasx2]", cmd_output) + self.assertIn("2 alias(es) have been successfully created: [aliasy1, aliasy2]", cmd_output) + print(f"Verified command output contains aliases") diff --git a/.github/workflows/tests/test_knox_configs.py b/.github/workflows/tests/test_knox_configs.py index 45947f01b6..0053eb8990 100644 --- a/.github/workflows/tests/test_knox_configs.py +++ b/.github/workflows/tests/test_knox_configs.py @@ -35,7 +35,7 @@ def setUp(self): self.base_url += "/" self.non_existent_path = self.base_url + "gateway/not-exists" - def test_auth_service_guest(self): + def test_global_hsts_header(self): """ Verifies header is present with the correct value """ diff --git a/.github/workflows/tests/util/knox.py b/.github/workflows/tests/util/knox.py new file mode 100644 index 0000000000..7b429d5cf4 --- /dev/null +++ b/.github/workflows/tests/util/knox.py @@ -0,0 +1,36 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to you under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import requests +import docker + +class Knox: + + def __init__(self, container_name): + """ + :param container_name: + """ + client = docker.from_env() + self.knox_container = client.containers.get(container_name) + + def run_knox_cmd(self, knox_cmd): + """ + :param knox_cmd: + :return: + """ + result = self.knox_container.exec_run(f"{knox_cmd}", stream=False) + output = result.output.decode() + print(f"\n[CMD={knox_cmd}] OUTPUT:\n{output}") + return output +