-
Notifications
You must be signed in to change notification settings - Fork 101
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
base: develop
Are you sure you want to change the base?
Changes from all commits
e06b396
8471ba1
f2b1434
106bee5
245d64e
4c556a3
529e7f6
198cf88
db82eb7
90a1c62
df4ae37
8dd2c9e
05f3c2c
aa47a09
1912fd4
77f21d3
cf2a3b9
c7ab2ae
34e7e33
b02854a
f94da54
458a978
2d59aa5
18a9e7c
ef326c2
3d328f9
2fa29ae
a796365
456b1c4
8cc06a1
b08bbdf
d7b4e6b
973deaf
8ee5d0a
2073c9b
faa974e
8d9d00c
3e56c4d
35a1d4b
1ce2013
54db2c0
804b36c
0bb9e34
6868c0c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,16 +25,22 @@ | |
limitations under the License. | ||
""" | ||
import os | ||
import argparse | ||
import pytest | ||
import mock | ||
import argparse | ||
from flask_testing import TestCase | ||
|
||
from mslib.mscolab.conf import mscolab_settings | ||
from mslib.mscolab.models import Operation, User, Permission | ||
from mslib.mscolab.mscolab import handle_db_reset, handle_db_seed, confirm_action, main | ||
from mslib.mscolab.mscolab import (handle_db_reset, handle_db_seed, confirm_action, main, | ||
handle_mscolab_certificate_init, handle_local_idp_certificate_init, | ||
handle_mscolab_backend_yaml_init, handle_mscolab_metadata_init, | ||
handle_local_idp_metadata_init) | ||
from mslib.mscolab.server import APP | ||
from mslib.mscolab.seed import add_operation | ||
from tests import constants | ||
|
||
mscolab_settings.MSCOLAB_SSO_DIR = constants.MSCOLAB_SSO_DIR | ||
|
||
|
||
def test_confirm_action(): | ||
|
@@ -114,3 +120,104 @@ def test_handle_db_seed(self): | |
assert len(all_users) == 10 | ||
all_permissions = Permission.query.all() | ||
assert len(all_permissions) == 17 | ||
|
||
def test_handle_mscolab_certificate_init(self): | ||
""" | ||
Test the initialization of the MSColab server certificate files. | ||
This function tests the initialization process of the MSColab server certificate files | ||
by calling the initialization function and checking if the generated key and | ||
certificate files contain the expected content. | ||
""" | ||
handle_mscolab_certificate_init() | ||
file_key = os.path.join(mscolab_settings.MSCOLAB_SSO_DIR, 'key_mscolab.key') | ||
key_content = '' | ||
with open(file_key, 'r', encoding='utf-8') as file: | ||
key_content = file.read() | ||
assert "-----BEGIN PRIVATE KEY-----" in key_content | ||
assert "-----END PRIVATE KEY-----" in key_content | ||
file_cert = os.path.join(mscolab_settings.MSCOLAB_SSO_DIR, 'crt_mscolab.crt') | ||
crt_content = '' | ||
with open(file_cert, 'r', encoding='utf-8') as file: | ||
crt_content = file.read() | ||
assert "-----BEGIN CERTIFICATE-----" in crt_content | ||
assert "-----END CERTIFICATE-----" in crt_content | ||
|
||
def test_handle_local_idp_certificate_init(self): | ||
""" | ||
Test the initialization of the local Identity Provider (IDP) certificate files. | ||
This function tests the initialization process of the local IDP certificate files | ||
by calling the initialization function and checking if the generated key and | ||
certificate files contain the expected content. | ||
""" | ||
|
||
handle_local_idp_certificate_init() | ||
file_key = os.path.join(mscolab_settings.MSCOLAB_SSO_DIR, 'key_local_idp.key') | ||
key_content = '' | ||
with open(file_key, 'r', encoding='utf-8') as file: | ||
key_content = file.read() | ||
assert "-----BEGIN PRIVATE KEY-----" in key_content | ||
assert "-----END PRIVATE KEY-----" in key_content | ||
file_crt = os.path.join(mscolab_settings.MSCOLAB_SSO_DIR, 'crt_local_idp.crt') | ||
crt_content = '' | ||
with open(file_crt, 'r', encoding='utf-8') as file: | ||
crt_content = file.read() | ||
assert "-----BEGIN CERTIFICATE-----" in crt_content | ||
assert "-----END CERTIFICATE-----" in crt_content | ||
|
||
def test_handle_mscolab_backend_yaml_init(self): | ||
""" | ||
Test the initialization of MScolab backend YAML configuration. | ||
This function tests the initialization process of the MScolab backend YAML | ||
""" | ||
|
||
handle_mscolab_backend_yaml_init() | ||
file_yaml = os.path.join(mscolab_settings.MSCOLAB_SSO_DIR, 'mss_saml2_backend.yaml') | ||
mss_saml2_backend_content = '' | ||
with open(file_yaml, 'r', encoding='utf-8') as file: | ||
mss_saml2_backend_content = file.read() | ||
assert "localhost_test_idp" in mss_saml2_backend_content | ||
assert "entityid_endpoint" in mss_saml2_backend_content | ||
|
||
def test_handle_mscolab_metadata_init(self): | ||
""" | ||
Test the initialization of MSColab server metadata. | ||
This function tests the initialization process of MSColab server metadata | ||
by calling several initialization functions and checking if the expected | ||
content is present in the generated metadata XML file. | ||
""" | ||
# set TESTING_USE_SAML2 and MSCOLAB_SSO_DIRthrough envs | ||
os.environ['TESTING_MSCOLAB_SSO_DIR'] = mscolab_settings.MSCOLAB_SSO_DIR | ||
os.environ['TESTING_USE_SAML2'] = "True" | ||
|
||
handle_mscolab_certificate_init() | ||
handle_mscolab_backend_yaml_init() | ||
mscolab_settings.USE_SAML2 = True | ||
assert handle_mscolab_metadata_init(True) is True | ||
metadata_xml = os.path.join(mscolab_settings.MSCOLAB_SSO_DIR, 'metadata_sp.xml') | ||
metadata_content = '' | ||
with open(metadata_xml, 'r', encoding='utf-8') as file: | ||
metadata_content = file.read() | ||
assert "urn:oasis:names:tc:SAML:2.0:metadata" in metadata_content | ||
|
||
def test_handle_local_idp_metadata_init(self): | ||
""" | ||
Test the initialization of local Identity Provider (IDP) metadata. | ||
This function tests the initialization process of local IDP metadata | ||
by calling several initialization functions and checking if the expected | ||
content is present in the generated metadata XML file. | ||
""" | ||
# set TESTING_USE_SAML2 and MSCOLAB_SSO_DIRthrough envs | ||
os.environ['TESTING_MSCOLAB_SSO_DIR'] = mscolab_settings.MSCOLAB_SSO_DIR | ||
os.environ['TESTING_USE_SAML2'] = "True" | ||
|
||
handle_local_idp_certificate_init() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there are also "print" outputs which can be compared, if they are the expected ones, e.g. https://pavolkutaj.medium.com/how-to-test-printed-output-in-python-with-pytest-and-its-capsys-fixture-161010cfc5ad |
||
handle_mscolab_backend_yaml_init() | ||
handle_mscolab_certificate_init() | ||
mscolab_settings.USE_SAML2 = True | ||
handle_mscolab_metadata_init(True) | ||
assert handle_local_idp_metadata_init(True) is True | ||
idp_xml = os.path.join(mscolab_settings.MSCOLAB_SSO_DIR, 'metadata_sp.xml') | ||
idp_content = '' | ||
with open(idp_xml, 'r', encoding='utf-8') as file: | ||
idp_content = file.read() | ||
assert "urn:oasis:names:tc:SAML:2.0:metadata" in idp_content |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for using the command you assume you are in the correct dir, this can make problems for handle_mscolab_metadata_init
You can get the path of mscolab.py by importing it and looking on
mscolab.__file__
Tests sometimes shows that also the code needs to become improved