diff options
| author | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-05-10 13:18:14 +0200 |
|---|---|---|
| committer | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-05-10 13:18:14 +0200 |
| commit | cd5019305db965b4e3acb028ec1f1524d0199917 (patch) | |
| tree | 798318aee35661a8e3d07da5e3b4e8a992d32052 | |
| parent | 9e3e7f22892c3504e6de9827af0fabd9b4b098ea (diff) | |
Python: Add config retrieval test
| -rw-r--r-- | ci/docker/go-test.docker | 44 | ||||
| -rw-r--r-- | selenium_eduvpn.py | 23 | ||||
| -rw-r--r-- | wrappers/python/Makefile | 2 | ||||
| -rw-r--r-- | wrappers/python/tests.py | 32 |
4 files changed, 71 insertions, 30 deletions
diff --git a/ci/docker/go-test.docker b/ci/docker/go-test.docker index 04b6a99..7636cae 100644 --- a/ci/docker/go-test.docker +++ b/ci/docker/go-test.docker @@ -8,35 +8,41 @@ WORKDIR /eduvpn # Firefox RUN echo "deb http://deb.debian.org/debian/ unstable main contrib non-free" >> /etc/apt/sources.list.d/debian.list RUN apt-get update -RUN apt-get -y install openjdk-11-jre xvfb python3-selenium firefox python3-pyvirtualdisplay +RUN apt-get -y install openjdk-11-jre xvfb python3-selenium firefox python3-pyvirtualdisplay python3-pip # Install geckodriver and add to path -WORKDIR /eduvpn/go/vendor - +WORKDIR /eduvpn/vendor RUN wget https://github.com/mozilla/geckodriver/releases/download/v0.30.0/geckodriver-v0.30.0-linux64.tar.gz RUN tar xzvf geckodriver-v0.30.0-linux64.tar.gz -ENV PATH="/eduvpn/go/vendor:$PATH" +ENV PATH="/eduvpn/vendor:$PATH" + +# Update certificates +COPY ./ci/docker/selfsigned/eduvpnserver.crt /usr/local/share/ca-certificates/eduvpnserver.crt +RUN update-ca-certificates -# Set up file tree -WORKDIR /eduvpn/go +# Run tests as a new user for pip +RUN useradd --create-home test +USER test -# Taken from golang docker example -# pre-copy/cache go.mod for pre-downloading dependencies and only redownloading them in subsequent builds if they change -COPY ./go.mod go.sum ./ +WORKDIR /home/test + +# Copy sources with correct permissions +COPY --chown=test:test . ./ + +# Download and verify go dependencies RUN go mod download && go mod verify -WORKDIR /eduvpn/go +# Clean because there might be previous builds copied over +RUN make clean -# Copy go source -COPY *.go ./ -COPY ./internal ./internal +# Build go +RUN make build -# Copy selenium scripts -COPY ./selenium_eduvpn.py ./selenium_eduvpn.py +# Make python lib +RUN make -C wrappers/python -# Update certificates -COPY ./ci/docker/selfsigned/eduvpnserver.crt /usr/local/share/ca-certificates/eduvpnserver.crt -RUN update-ca-certificates +# Install python lib +RUN pip3 install wrappers/python/dist/*.whl # Run the tests -CMD ["go", "test", "-mod=readonly", "./...", "-v"] +CMD ["make", "test"]
\ No newline at end of file diff --git a/selenium_eduvpn.py b/selenium_eduvpn.py index 6c91fa5..76e86aa 100644 --- a/selenium_eduvpn.py +++ b/selenium_eduvpn.py @@ -5,6 +5,18 @@ from selenium.webdriver.common.keys import Keys from selenium.webdriver.firefox.options import Options +def login_eduvpn(authURL): + options = Options() + options.headless = True + + # Use the firefox driver + driver = webdriver.Firefox(options=options) + + login_oauth(driver, authURL) + + # Cleanup + driver.close() + # Logs in to the default vpn user portal with selenium def login_oauth(driver, authURL): # Go to the oauth url and verify the title @@ -51,15 +63,6 @@ if __name__ == "__main__": print("Error: no auth url specified") sys.exit(1) - options = Options() - options.headless = True - - # Use the firefox driver - driver = webdriver.Firefox(options=options) - # Login to the portal authURL = sys.argv[1] - login_oauth(driver, authURL) - - # Cleanup - driver.close() + login_eduvpn(authURL) diff --git a/wrappers/python/Makefile b/wrappers/python/Makefile index 92482a4..22e9144 100644 --- a/wrappers/python/Makefile +++ b/wrappers/python/Makefile @@ -14,7 +14,7 @@ pack: test: .try-build-lib install "$(EXPORTS_LIB_SUBFOLDER_PATH)/$(LIB_FILE)" -Dt "eduvpncommon/lib" - #python3 -m unittest test_discovery + python3 -m unittest tests rm eduvpncommon/lib/* clean: diff --git a/wrappers/python/tests.py b/wrappers/python/tests.py new file mode 100644 index 0000000..f006646 --- /dev/null +++ b/wrappers/python/tests.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python3 + +import unittest +import eduvpncommon.main as eduvpn +import webbrowser +import sys +import os + +# Import project root directory where the selenium python utility is +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) + +from selenium_eduvpn import login_eduvpn + +class ConfigTests(unittest.TestCase): + def testConfig(self): + self._eduvpn = eduvpn.EduVPN("org.eduvpn.app.linux", "testconfigs") + assert self._eduvpn.register() + @self._eduvpn.event.on("OAuth_Started", eduvpn.StateType.Enter) + def oauth_initialized(url): + login_eduvpn(url) + + server_uri = os.getenv("SERVER_URI") + if not server_uri: + self.fail("No SERVER_URI environment variable given") + + config, error = self._eduvpn.get_config_institute_access(server_uri) + + if error != "": + self.fail(f"Got error: {error} when connecting to {server_uri}") + +if __name__ == "__main__": + unittest.main() |
