Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Functional tests implementation for mscolab.py file #2065

Draft
wants to merge 44 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
e06b396
remove inputs from conditions (#1808)
nilupulmanodya Jun 10, 2023
8471ba1
Setup sp and idp for the sso (#1809)
nilupulmanodya Jun 15, 2023
f2b1434
Split conf sp idp (#1811)
nilupulmanodya Jun 28, 2023
106bee5
UI changes in Qt for SSO (#1813)
nilupulmanodya Jul 21, 2023
245d64e
web browser implementation (#1814)
nilupulmanodya Jul 25, 2023
4c556a3
Configure mscolab for sso (#1818)
nilupulmanodya Aug 1, 2023
529e7f6
To do fixes #1818 (#1974)
nilupulmanodya Sep 24, 2023
198cf88
improve code for multiple Idps
nilupulmanodya Sep 24, 2023
db82eb7
conf routes for multiple conf
nilupulmanodya Oct 6, 2023
90a1c62
remove uncessary .yaml
nilupulmanodya Oct 6, 2023
df4ae37
update cmd metadata
nilupulmanodya Oct 6, 2023
8dd2c9e
update conf
nilupulmanodya Oct 6, 2023
05f3c2c
update saml handler for multiple idps
nilupulmanodya Oct 7, 2023
aa47a09
pinning of xmlschema
nilupulmanodya Oct 9, 2023
1912fd4
pin werkzeug
nilupulmanodya Oct 9, 2023
77f21d3
disable pytests for todo refactor
nilupulmanodya Oct 10, 2023
cf2a3b9
disbale whole file gsoc_testing
nilupulmanodya Oct 10, 2023
c7ab2ae
fix conf
nilupulmanodya Oct 11, 2023
34e7e33
resolve comments
nilupulmanodya Oct 12, 2023
b02854a
resolve comments
nilupulmanodya Oct 14, 2023
f94da54
Merge pull request #2043 from nilupulmanodya/implement-mscolab-for-mu…
ReimarBauer Oct 15, 2023
458a978
Merge branch 'develop' of https://github.com/nilupulmanodya/MSS into …
nilupulmanodya Oct 16, 2023
2d59aa5
manual conflict resolve ui_mscolab_connect_dialog.ui file
nilupulmanodya Oct 16, 2023
18a9e7c
resolve flake8
nilupulmanodya Oct 16, 2023
ef326c2
Merge pull request #2061 from nilupulmanodya/merge_current_develop
ReimarBauer Oct 19, 2023
3d328f9
set SSL certificate verification enablement (#2062)
nilupulmanodya Oct 19, 2023
2fa29ae
functional test cases implementation mscolab.py
nilupulmanodya Oct 24, 2023
a796365
resolove flake8
nilupulmanodya Oct 24, 2023
456b1c4
Revert "resolove flake8"
nilupulmanodya Oct 24, 2023
8cc06a1
Revert "Revert "resolove flake8""
nilupulmanodya Oct 24, 2023
b08bbdf
resolve flake8
nilupulmanodya Oct 24, 2023
d7b4e6b
recorrect commit
nilupulmanodya Oct 24, 2023
973deaf
fix flake8 test_mscolab.py
nilupulmanodya Oct 24, 2023
8ee5d0a
set fixed dir for crts keys and metadata xmls
nilupulmanodya Oct 31, 2023
2073c9b
fixes pylint
nilupulmanodya Oct 31, 2023
faa974e
Merge branch 'develop' of https://github.com/nilupulmanodya/MSS into …
nilupulmanodya Nov 11, 2023
8d9d00c
implement constants through envs
nilupulmanodya Nov 11, 2023
3e56c4d
set env through test_mscolab.py
nilupulmanodya Nov 11, 2023
35a1d4b
set abs path
nilupulmanodya Nov 11, 2023
1ce2013
Merge remote-tracking branch 'origin/develop' into functional-tests-i…
nilupulmanodya Nov 27, 2023
54db2c0
resolve pull conflicts
nilupulmanodya Nov 27, 2023
804b36c
resolve pull conflicts
nilupulmanodya Nov 27, 2023
0bb9e34
set env TESTING_MSCOLAB_SSO_DIR idp_conf.py
nilupulmanodya Nov 30, 2023
6868c0c
test with sys.path
nilupulmanodya Dec 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ build/
mss.egg-info/
tutorials/recordings
tutorials/cursor_image.png

__pycache__/
instance/
11 changes: 11 additions & 0 deletions NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,14 @@ License: https://github.com/PaulSchweizer/qt-json-view/blob/master/LICENSE (MIT

Package for working with JSON files in PyQt5.
Obtained from Github (https://github.com/PaulSchweizer/qt-json-view), on 23/7/2021.

Identity Provider
-----------------

We utilize example files from the pysaml2 library to set up the configuration for our local Identity Provider (IdP).
Obtained from GitHub (https://github.com/IdentityPython/pysaml2/tree/master/example/idp2) on 13/07/2023

Copyright: 2018 Roland Hedberg

License: https://github.com/IdentityPython/pysaml2/blob/master/LICENSE (Apache License 2.0)
Further Information: https://pysaml2.readthedocs.io/en/
7 changes: 5 additions & 2 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import os
import sys
import mock
import warnings
from PyQt5 import QtWidgets
# Disable pyc files
sys.dont_write_bytecode = True
Expand Down Expand Up @@ -125,6 +124,8 @@ def pytest_generate_tests(metafunc):
# mscolab data directory
MSCOLAB_DATA_DIR = fs.path.join(DATA_DIR, 'filedata')



# In the unit days when Operations get archived because not used
ARCHIVE_THRESHOLD = 30

Expand Down Expand Up @@ -182,6 +183,9 @@ def pytest_generate_tests(metafunc):
</FlightTrack>
"""
enable_basic_http_authentication = False

# enable login by identity provider
USE_SAML2 = False
'''
ROOT_FS = fs.open_fs(constants.ROOT_DIR)
if not ROOT_FS.exists('mscolab'):
Expand Down Expand Up @@ -234,7 +238,6 @@ def fail_if_open_message_boxes_left():
for box in [q, i, c, w] if box.call_count > 0])
pytest.fail(f"An unhandled message box popped up during your test!\n{summary}")


# Try to close all remaining widgets after each test
for qobject in set(QtWidgets.QApplication.topLevelWindows() + QtWidgets.QApplication.topLevelWidgets()):
try:
Expand Down
4 changes: 2 additions & 2 deletions docs/components.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ Components
mscolab
gentutorials
mssautoplot


conf_auth_client_sp_idp
conf_sso_test_msscolab
87 changes: 87 additions & 0 deletions docs/conf_auth_client_sp_idp.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
Identity Provider and Testing Service Provider for testing the SSO process
==========================================================================
Both ``auth_client_sp`` and ``idp`` are designed specifically for testing the Single Sign-On (SSO) process using PySAML2. These folders encompass both the Identity Provider (IdP) and Service Provider (SP) implementations, which are utilized on a local server.

The Identity Provider was set up following the official documentation of https://pysaml2.readthedocs.io/en/latest/, along with examples provided in the repository. Metadata YAML files will generate using the built-in tools of PySAML2. Actual key and certificate files can be used in when actual implementation. Please note that this both identity provider(IDP) and service provider(SP) is intended for testing purposes only.

Getting started
---------------

TLS Setup
---------

**Setting Up Certificates for Local Development**


To set up the certificates for local development, follow these steps:

1. Generate a primary key `(.key)` and a certificate `(.crt)` files using any certificate authority tool. You will need one for the service provider and another one for the identity provider. Make sure to name certificate of identity provider as `crt_idp.crt` and key as `key_idp.key`. Also name the certificate of service provider as `crt_sp.crt` and key as the `key_sp.key`.

Here's how you can generate self-signed certificates and private keys using OpenSSL:

* Generate a self-signed certificate and private key for the Service Provider (SP)

``openssl req -newkey rsa:4096 -keyout key_sp.key -nodes -x509 -days 365 -out crt_sp.crt``

* Generate a self-signed certificate and private key for the Identity Provider (IdP)

``openssl req -newkey rsa:4096 -keyout key_idp.key -nodes -x509 -days 365 -out crt_idp.crt``

2. Copy and paste the certificate and private key into the following file directories:

- Key and certificate of Service Provider: ``MSS/mslib/auth_client_sp/``

- key and certificate of Identity Provider:
Since mscolab server's path was set as the default path for the key and certificate, you should manually update the path of `SERVER_CERT` with the path of the generated `.crt` file for IDP, and `SERVER_KEY` with the path of the generated `.key` file for the IDP in the file `MSS/mslib/idp/idp_conf.py`


Make sure to insert the key along with its corresponding certificate.

Configuring the Service Provider and Identity Provider
------------------------------------------------------

First, generate the metadata file (https://pysaml2.readthedocs.io/en/latest/howto/config.html#metadata) for the service provider. To do that, start the Flask application and download the metadata file by following these steps:

1. Navigate to the home directory, ``/MSS/``.
2. Start the Flask application by running ``$ python mslib/auth_client_sp/app/app.py`` The application will listen on port : 5000.
3. Download the metadata file by executing the command: ``curl http://localhost:5000/metadata/ -o sp.xml``.
4. Move generated ``sp.xml`` to dir ``MSS/mslib/idp/`` and update path of `["metadata"]["local"]` accordingly.

After that, generate the idp.xml file, copy it over to the Service Provider (SP), and restart the SP Flask application:

5. Go to the directory ``MSS/``.
6. Run the command
``$ make_metadata mslib/idp/idp_conf.py > mslib/auth_client_sp/idp.xml``

This executes the make_metadata tool from pysaml2, then saved XML content to the specified output file in the service provider dir: ``MSS/mslib/auth_client_sp/idp.xml``.

Running the Application After Configuration
-------------------------------------------

Once you have successfully configured the Service Provider and the Identity Provider, you don't need to follow the above instructions again. To start the application after the initial configuration, follow these steps:

1. Start the Service provider:

* Navigate to the directory ``MSS/`` and run

``$ python mslib/auth_client_sp/app/app.py``

2. Start the Identity Provider:

* Navigate to the directory ``MSS/`` and run

``$ python mslib/idp/idp.py idp_conf``

By following the provided instructions, you will be able to set up and configure both the Identity Provider and Service Provider for testing the SSO process.

Testing Single Sign-On (SSO) process
------------------------------------

* Once you have successfully launched the server and identity provider, you can begin testing the Single Sign-On (SSO) process.
* Load in a browser http://127.0.0.1:5000/.
* To log in to the service provider through the identity provider, you can use the credentials specified in the ``PASSWD`` section of the ``MSS/mslib/idp/idp.py`` file. Look for the relevant section in the file to find the necessary login credentials.

References
----------

* https://pysaml2.readthedocs.io/en/latest/examples/idp.html
117 changes: 117 additions & 0 deletions docs/conf_sso_test_msscolab.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
Configuration MSS Colab Server with Testing IdP for SSO
=======================================================
Testing IDP (`mslib/msidp`) is specifically designed for testing the Single Sign-On (SSO) process with the mscolab server using PySAML2.

Here is documentation that explains the configuration of the MSS Colab Server with the testing IdP.

Getting started
---------------

To set up a local identity provider with the mscolab server, you'll first need to generate the required keys and certificates for both the Identity Provider and the mscolab server. Follow these steps to configure the system:

1. Initial Steps
2. Generate Keys and Certificates
3. Enable USE_SAML2
4. Generate Metadata Files
5. Start the Identity Provider
6. Start the mscolab Server
7. Test the Single Sign-On (SSO) Process


1. Initial Steps
----------------
Before getting started, you should correctly activate the environments, set the correct Python path as explained in the mss instructions : https://github.com/Open-MSS/MSS/tree/develop#readme



2. Generate Keys, Certificates, and backend_saml files
------------------------------------------------------

This involves generating both `.key` files and `.crt` files for both the Identity provider and mscolab server and `backend_saml.yaml` file.

Before running the command make sure to set `USE_SAML2 = False` in your `mscolab_settings.py` file, You can accomplish this by following these steps:

- Add to the `PYTHONPATH` where your `mscolab_settings.py`.
- Add `USE_SAML2 = False` in your `mscolab_settings.py` file.

.. note::
If you set `USE_SAML2 = True` without keys and certificates, this will not execute. So, make sure to set `USE_SAML2 = False` before executing the command.

If everything is correctly set, you can generate keys and certificates simply by running

.. code:: text

$ mscolab sso_conf --init_sso_crts

.. note::
This process generating keys and certificates for both Identity provider and mscolab server by default, If you need configure with different keys and certificates for the Identity provider, You should manually update the path of `SERVER_CERT` with the path of the generated .crt file for Identity provider, and `SERVER_KEY` with the path of the generated .key file for the Identity provider in the file `MSS/mslib/idp/idp_conf.py`.


3. Enable USE_SAML2
-------------------

To enable SAML2-based login (identity provider-based login),

- To start the process update `USE_SAML2 = True` in your `mscolab_settings.py` file.

.. note::
After enabling the `USE_SAML2` option, the subsequent step involves adding the `CONFIGURED_IDPS` dictionary for the MSS Colab Server. This dictionary must contain keys for each active Identity Provider, denoted by their `idp_identity_name`, along with their respective `idp_name`. Once this dictionary is configured, it should be utilized to update several aspects of the mscolab server, including the SAML2Client configuration in the .yml file. This ensures seamless integration with the enabled IDPs. By default, configuration has been set up for the localhost IDP, and any additional configurations required should be performed by the developer.

4. Generate metadata files
--------------------------

This involves generating necessary metadata files for both the identity provider and the service provider. You can generate them by simply running the below command.

.. note::
Before executing this, you should set `USE_SAML2=True` as described in the third step(Enable USE_SAML2).

.. code:: text

$ mscolab sso_conf --init_sso_metadata


5. Start Identity provider
--------------------------

Once you set certificates and metada files you can start mscolab server and local identity provider. To start local identity provider, simply execute:

.. code:: text

$ msidp


6. Start the mscolab Server
---------------------------

Before Starting the mscolab server, make sure to do necessary database migrations.

When this is the first time you setup a mscolab server, you have to initialize the database by:

.. code:: text

$ mscolab db --init

.. note::
An existing database maybe needs a migration, have a look for this on our documentation.

https://mss.readthedocs.io/en/stable/mscolab.html#data-base-migration

When migrations finished, you can start mscolab server using the following command:

.. code:: text

$ mscolab start


7. Testing Single Sign-On (SSO) process
---------------------------------------

* Once you have successfully launched the server and identity provider, you can begin testing the Single Sign-On (SSO) process.
* Start MSS PyQt application:

.. code:: text

$ msui

* Login with identity provider through Qt Client application.
* To log in to the mscolab server through the identity provider, you can use the credentials specified in the ``PASSWD`` section of the ``MSS/mslib/msidp/idp.py`` file. Look for the relevant section in the file to find the necessary login credentials.
3 changes: 3 additions & 0 deletions docs/samples/config/mscolab/mscolab_settings.py.sample
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ STUB_CODE = """<?xml version="1.0" encoding="utf-8"?>
</FlightTrack>
"""

# enable login by identity provider
USE_SAML2 = False

# looks for a given category forn a operation ending with GROUP_POSTFIX
# e.g. category = Tex will look for TexGroup
# all users in that Group are set to the operations of that category
Expand Down
5 changes: 5 additions & 0 deletions localbuild/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ build:
- mswms_demodata = mslib.mswms.demodata:main
- mscolab = mslib.mscolab.mscolab:main
- mssautoplot = mslib.utils.mssautoplot:main
- msidp = mslib.msidp.idp:main

requirements:
build:
Expand Down Expand Up @@ -92,6 +93,9 @@ requirements:
- email_validator
- keyring
- dbus-python
- flask-login
- pysaml2
- libxmlsec1

test:
imports:
Expand All @@ -101,6 +105,7 @@ test:
- mswms_demodata -h
- msui -h
- mscolab -h
- msidp -h

about:
summary: 'A web service based tool to plan atmospheric research flights.'
Expand Down
11 changes: 11 additions & 0 deletions mslib/auth_client_sp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Flask Service Provider with PySAML2 Integration

This is a simple Flask service provider that allows for single sign-on (SSO) authentication using PySAML2.

## Features

- Integration with PySAML2 for SSO authentication.
- Securely handles SAML assertions and authentication responses.
- Provides routes for login, logout, and profile endpoints.
- Uses SQLAlchemy database for user management.
- Supports both HTTP Redirect and HTTP POST bindings for SAML responses.
Loading
Loading