Skip to content

Commit 06691f4

Browse files
committed
refactor: add Dockerfile for mock
1 parent 55bf8cb commit 06691f4

File tree

15 files changed

+662
-33
lines changed

15 files changed

+662
-33
lines changed

CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ OPTION(BUILD_TESTS "Build Tests" TRUE)
2828
OPTION(BUILD_WEB_SERVER "Build DataFed Web Server" TRUE)
2929
OPTION(ENABLE_UNIT_TESTS "Enable unit tests" TRUE)
3030
OPTION(ENABLE_INTEGRATION_TESTS "Enable integration tests" TRUE)
31+
OPTION(BUILD_MOCK_CORE "Enable integration tests" FALSE)
3132
OPTION(ENABLE_MEMORY_TESTS "Enable memory tests" FALSE)
3233
OPTION(BUILD_SHARED_LIBS "By default DataFed tries to build static libraries
3334
with the exception of libdatafed-authz which must always be a shared library,
@@ -44,6 +45,7 @@ OPTION(ENABLE_FOXX_TESTS "Enable Foxx testing, off by default because it
4445
set(INSTALL_REPO_SERVER ${BUILD_REPO_SERVER})
4546
set(INSTALL_AUTHZ ${BUILD_AUTHZ})
4647
set(INSTALL_CORE_SERVER ${BUILD_CORE_SERVER})
48+
set(INSTALL_MOCK_CORE_SERVER ${BUILD_MOCK_CORE_SERVER})
4749
set(INSTALL_WEB_SERVER ${BUILD_WEB_SERVER})
4850

4951
set(DATAFED_CONFIG_SH "${DataFed_SOURCE_DIR}/config/datafed.sh")
@@ -190,7 +192,7 @@ endif()
190192

191193
# Must occur before building authz, location of mock keys are defined here
192194
# ENV DATAFED_MOCK_CORE_PUB_KEY
193-
if (ENABLE_INTEGRATION_TESTS OR ENABLE_END_TO_END_TESTS)
195+
if (ENABLE_INTEGRATION_TESTS OR ENABLE_END_TO_END_TESTS OR BUILD_MOCK_CORE)
194196
add_subdirectory(tests)
195197
endif()
196198

core/server/ClientWorker.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
// Local DataFed includes
33
#include "ClientWorker.hpp"
4+
#include "ICoreServer.hpp"
45
#include "TaskMgr.hpp"
56
#include "Version.hpp"
67

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
cmake_minimum_required (VERSION 3.17.0)
2+
# 3.7.0 requires to use test fixtures
3+
4+
if( ENABLE_INTEGRATION_TESTS )
5+
# Each test listed in Alphabetical order
6+
foreach(PROG
7+
test_MessageLib
8+
)
9+
10+
add_test(NAME integration_${PROG}
11+
COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/${PROG}"
12+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/tests/mock_core
13+
)
14+
15+
set_tests_properties(integration_${PROG} PROPERTIES FIXTURES_REQUIRED FIX_MOCK)
16+
17+
endforeach(PROG)
18+
endif()
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
3+
class Defaults:
4+
5+
mock_core_server_public_key = "2n!B./}BqNbqJ3.Xy6&bBZf>JHq$][AXcIU-xd-M"
6+
mock_core_server_host = "localhost"
7+
mock_core_server_port = 9998
8+
mock_python_client_public_key = "Yne@$w-vo<fVvi]a<NY6T1ed:M$fCG*[IaLV{hID"
9+
mock_python_client_private_key = "D:)Q[IlAW!ahhC2ac:9*A}h:p?([4%wOTJ%JR%cs"
10+
mock_authenticated_test_user = "authenticated_bob"
11+
test_user_password = "open_sesame"
12+
test_user_token = "validToken-4KDl-90ufsdfFDPPher0%lkfda"
13+
14+
mock_repo_address = "tcp://localhost:10000"
15+
mock_repo_id = "samoas"
16+
mock_repo_title = "Samoas are the best girl scout cookie"
17+
mock_repo_capacity = 100000
18+
mock_repo_desc = "There really is no comparison"
19+
mock_repo_globus_uuid = "550e8400-e29b-41d4-a716-446655440000"
20+
mock_repo_path = "/mnt/data/samoas"
21+
mock_repo_type = "globus"
22+
mock_repo_pub_key = "Wxwm^-Cf7cJrqS)}/B?cDAq(L=@AwSA*({jhBu1]"
23+
mock_repo_admin = mock_authenticated_test_user
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
#!/usr/bin/env python3
2+
# WARNING - to work with python environments we cannot use /bin/python3 or
3+
# a hardcoded abs path.
4+
"""
5+
Integration tests for DataFed MessageLib.API class.
6+
7+
These tests assume a mock DataFed service is running externally and will
8+
interact with it to test various scenarios including connection establishment,
9+
authentication, message handling, and error conditions.
10+
"""
11+
12+
import pytest
13+
import os
14+
import tempfile
15+
import time
16+
import zmq
17+
18+
# Assuming the module structure based on the imports in the source file
19+
from datafed import CommandLib
20+
from datafed import SDMS_Anon_pb2 as anon
21+
from datafed import SDMS_Auth_pb2 as auth
22+
from datafed import Version_pb2
23+
from mock_defaults import Defaults
24+
25+
# Test configuration - adjust these based on your mock service setup
26+
27+
28+
@pytest.fixture
29+
def command_lib_options():
30+
"""Create temporary key files for testing."""
31+
with tempfile.TemporaryDirectory() as temp_dir:
32+
33+
server_key_file = os.getenv("DATAFED_MOCK_CORE_PUB_KEY", os.path.join(temp_dir, "server.key"))
34+
client_pub_key_file = os.path.join(temp_dir, "client.pub")
35+
client_priv_key_file = os.path.join(temp_dir, "client.priv")
36+
37+
if os.path.exists(server_key_file):
38+
# grab the key from the file instead of writing the default key
39+
# to the file.
40+
with open(server_key_file, "r") as f:
41+
server_key = f.read().strip()
42+
else:
43+
with open(server_key_file, 'w') as f:
44+
f.write(Defaults.mock_core_server_public_key)
45+
server_key = Defaults.mock_core_server_public_key
46+
47+
with open(client_pub_key_file, 'w') as f:
48+
f.write(Defaults.mock_python_client_public_key)
49+
with open(client_priv_key_file, 'w') as f:
50+
f.write(Defaults.mock_python_client_private_key)
51+
52+
yield {
53+
'client_pub_key_file': client_pub_key_file,
54+
'client_priv_key_file': client_priv_key_file,
55+
'server_pub_key_file': server_key_file,
56+
'server_port': Defaults.mock_core_server_port,
57+
'server_host': Defaults.mock_core_server_host
58+
}
59+
60+
@pytest.fixture
61+
def repo_create_options():
62+
"""Create temporary key files for testing."""
63+
yield {
64+
'repo_id': Defaults.mock_repo_id,
65+
'title': Defaults.mock_repo_title,
66+
'desc': Defaults.mock_repo_desc,
67+
'capacity': Defaults.mock_repo_capacity,
68+
'pub_key': Defaults.mock_repo_pub_key,
69+
'address': Defaults.mock_repo_address,
70+
'endpoint': Defaults.mock_repo_globus_uuid,
71+
'path': Defaults.mock_repo_path,
72+
'type': Defaults.mock_repo_type,
73+
'admins': [Defaults.mock_repo_admin]
74+
}
75+
76+
77+
class TestCommandLibRepo:
78+
"""Test various connection establishment scenarios."""
79+
80+
def test_successful_connection_with_key_files(self, command_lib_options, repo_create_options):
81+
"""Test successful connection using key files."""
82+
api = CommandLib.API(command_lib_options)
83+
84+
api.loginByPassword(Defaults.mock_authenticated_test_user, Defaults.test_user_password)
85+
86+
result = api.repoCreate(
87+
repo_id=repo_create_options["repo_id"],
88+
title=repo_create_options["title"],
89+
desc=repo_create_options["desc"],
90+
capacity=repo_create_options["capacity"],
91+
pub_key=repo_create_options["pub_key"],
92+
address=repo_create_options["address"],
93+
endpoint=repo_create_options["endpoint"],
94+
path=repo_create_options["path"],
95+
admins=repo_create_options["admins"],
96+
domain='',
97+
exp_path=''
98+
)
99+
100+
print("Result is")
101+
print(result)
102+
repo = result[0].repo[0]
103+
print(repo)
104+
print("Admins")
105+
print(repo.admin)
106+
assert repo.id == f"repo/{repo_create_options['repo_id']}"
107+
assert repo.title == repo_create_options['title']
108+
assert repo.desc == repo_create_options['desc']
109+
assert repo.capacity == repo_create_options['capacity']
110+
assert repo.pub_key == repo_create_options['pub_key']
111+
assert repo.address == repo_create_options['address']
112+
assert repo.endpoint == repo_create_options['endpoint']
113+
assert repo.admin == repo_create_options['admins']
114+
assert repo.type == repo_create_options['type']
115+
116+
if __name__ == "__main__":
117+
pytest.main([__file__, "-v"])

0 commit comments

Comments
 (0)