Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
0724cb1
added tests for report endpoints
MariusBaldovin Aug 14, 2024
1798392
added tests for certificate endpoints
MariusBaldovin Aug 14, 2024
70aef96
fix report.json
MariusBaldovin Aug 14, 2024
f925fb8
removed responses library, not used in testing
MariusBaldovin Aug 15, 2024
b94bb51
updated the test for /system/version endpoint
MariusBaldovin Aug 15, 2024
57d8105
Merge branch 'google:dev' into dev
MariusBaldovin Aug 15, 2024
3eb3fe6
fix pylint error
MariusBaldovin Aug 15, 2024
2f7a912
improved the code structure
MariusBaldovin Aug 15, 2024
c5361c9
removed timestamp variable in few tests
MariusBaldovin Aug 15, 2024
45ae6ee
Merge branch 'google:dev' into dev
MariusBaldovin Aug 16, 2024
277dc83
Merge branch 'google:dev' into dev
MariusBaldovin Aug 19, 2024
843a8ad
Merge branch 'google:dev' into dev
MariusBaldovin Aug 22, 2024
053fcd5
updated create_report_folder and test_system_version
MariusBaldovin Aug 22, 2024
58db257
Merge branch 'dev' into dev
jboddey Aug 22, 2024
05bcb88
Merge branch 'google:dev' into dev
MariusBaldovin Aug 23, 2024
b91a2dd
fixed test_api.py failing tests
MariusBaldovin Aug 23, 2024
4fdd30a
removed 2 unnecessary lines
MariusBaldovin Aug 23, 2024
8ecdf4f
Merge branch 'google:dev' into dev
MariusBaldovin Aug 23, 2024
d1f6dc4
fixed f string error
MariusBaldovin Aug 23, 2024
e897f2a
Merge branch 'google:dev' into dev
MariusBaldovin Aug 23, 2024
368bb6d
Merge branch 'google:dev' into dev
MariusBaldovin Aug 27, 2024
dc48fa8
Merge branch 'dev' into dev
MariusBaldovin Aug 28, 2024
3c2c1af
corrected the testrun session variable name
Aug 28, 2024
fbfe34c
Merge branch 'google:dev' into dev
MariusBaldovin Aug 29, 2024
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
48 changes: 39 additions & 9 deletions framework/python/src/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ async def delete_report(self, request: Request, response: Response):

if len(body_raw) == 0:
response.status_code = 400
return self._generate_msg(False, "Invalid request received")
return self._generate_msg(False, "Invalid request received, missing body")

try:
body_json = json.loads(body_raw)
Expand All @@ -445,12 +445,18 @@ async def delete_report(self, request: Request, response: Response):

if "mac_addr" not in body_json or "timestamp" not in body_json:
response.status_code = 400
return self._generate_msg(False, "Invalid request received")
return self._generate_msg(False, "Missing mac address or timestamp")

mac_addr = body_json.get("mac_addr").lower()
timestamp = body_json.get("timestamp")
parsed_timestamp = datetime.strptime(timestamp, "%Y-%m-%d %H:%M:%S")
timestamp_formatted = parsed_timestamp.strftime("%Y-%m-%dT%H:%M:%S")

try:
parsed_timestamp = datetime.strptime(timestamp, "%Y-%m-%d %H:%M:%S")
timestamp_formatted = parsed_timestamp.strftime("%Y-%m-%dT%H:%M:%S")

except ValueError:
response.status_code = 400
return self._generate_msg(False, "Incorrect timestamp format")

# Get device from MAC address
device = self._session.get_device(mac_addr)
Expand Down Expand Up @@ -541,7 +547,7 @@ async def save_device(self, request: Request, response: Response):
)

# Check if device folder exists
device_folder = os.path.join(self._test_run.get_root_dir(),
device_folder = os.path.join(self._testrun.get_root_dir(),
DEVICES_PATH,
device_json.get(DEVICE_MANUFACTURER_KEY) +
" " +
Expand Down Expand Up @@ -647,6 +653,12 @@ async def edit_device(self, request: Request, response: Response):
async def get_report(self, response: Response, device_name, timestamp):
device = self._session.get_device_by_name(device_name)

# If the device not found
if device is None:
LOGGER.info("Device not found, returning 404")
response.status_code = 404
return self._generate_msg(False, "Device not found")

# 1.3 file path
file_path = os.path.join(
DEVICES_PATH,
Expand Down Expand Up @@ -700,16 +712,34 @@ async def get_results(self, request: Request, response: Response, device_name,
return self._generate_msg(False,
"A device with that name could not be found")

file_path = self._get_testrun().get_test_orc().zip_results(
# Check if report exists (1.3 file path)
report_file_path = os.path.join(
DEVICES_PATH,
device_name,
"reports",
timestamp,"test",
device.mac_addr.replace(":",""))

if not os.path.isdir(report_file_path):
# pre 1.3 file path
report_file_path = os.path.join(DEVICES_PATH, device_name, "reports",
timestamp)

if not os.path.isdir(report_file_path):
LOGGER.info("Report could not be found, returning 404")
response.status_code = 404
return self._generate_msg(False, "Report could not be found")

zip_file_path = self._get_testrun().get_test_orc().zip_results(
device, timestamp, profile)

if file_path is None:
if zip_file_path is None:
response.status_code = status.HTTP_500_INTERNAL_SERVER_ERROR
return self._generate_msg(
False, "An error occurred whilst archiving test results")

if os.path.isfile(file_path):
return FileResponse(file_path)
if os.path.isfile(zip_file_path):
return FileResponse(zip_file_path)
else:
LOGGER.info("Test results could not be found, returning 404")
response.status_code = 404
Expand Down
2 changes: 0 additions & 2 deletions framework/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ pydantic==2.7.1
# Requirements for testing
pytest==7.4.4
pytest-timeout==2.2.0
responses==0.25.3


# Requirements for the report
markdown==3.5.2
Expand Down
29 changes: 29 additions & 0 deletions testing/api/certificates/WR2.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
-----BEGIN CERTIFICATE-----
MIIFCzCCAvOgAwIBAgIQf/AFoHxM3tEArZ1mpRB7mDANBgkqhkiG9w0BAQsFADBH
MQswCQYDVQQGEwJVUzEiMCAGA1UEChMZR29vZ2xlIFRydXN0IFNlcnZpY2VzIExM
QzEUMBIGA1UEAxMLR1RTIFJvb3QgUjEwHhcNMjMxMjEzMDkwMDAwWhcNMjkwMjIw
MTQwMDAwWjA7MQswCQYDVQQGEwJVUzEeMBwGA1UEChMVR29vZ2xlIFRydXN0IFNl
cnZpY2VzMQwwCgYDVQQDEwNXUjIwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEK
AoIBAQCp/5x/RR5wqFOfytnlDd5GV1d9vI+aWqxG8YSau5HbyfsvAfuSCQAWXqAc
+MGr+XgvSszYhaLYWTwO0xj7sfUkDSbutltkdnwUx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k8R+dDXSqv1MbRT1ybB5W0k8878XSOjvmiYTDIfyc9acxVJr
Y/cykHipa+te1pOhv7wYPYtZ9orGBV5SGOJm4NrB3K1aJar0RfzxC3ikr7Dyc6Qw
qDTBU39CluVIQeuQRgwG3MuSxl7zRERDRilGoKb8uY45JzmxWuKxrfwT/478JuHU
/oTxUFqOl2stKnn7QGTq8z29W+GgBLCXSBxC9epaHM0myFH/FJlniXJfHeytWt0=
-----END CERTIFICATE-----
31 changes: 31 additions & 0 deletions testing/api/certificates/crt.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
-----BEGIN CERTIFICATE-----
MIIFVzCCAz+gAwIBAgINAgPlk28xsBNJiGuiFzANBgkqhkiG9w0BAQwFADBHMQsw
CQYDVQQGEwJVUzEiMCAGA1UEChMZR29vZ2xlIFRydXN0IFNlcnZpY2VzIExMQzEU
MBIGA1UEAxMLR1RTIFJvb3QgUjEwHhcNMTYwNjIyMDAwMDAwWhcNMzYwNjIyMDAw
MDAwWjBHMQswCQYDVQQGEwJVUzEiMCAGA1UEChMZR29vZ2xlIFRydXN0IFNlcnZp
Y2VzIExMQzEUMBIGA1UEAxMLR1RTIFJvb3QgUjEwggIiMA0GCSqGSIb3DQEBAQUA
A4ICDwAwggIKAoICAQC2EQKLHuOhd5s73L+UPreVp0A8of2C+X0yBoJx9vaMf/vo
27xqLpeXo4xL+Sv2sfnOhB2x+cWX3u+58qPpvBKJXqeqUqv4IyfLpLGcY9vXmX7w
Cl7raKb0xlpHDU0QM+NOsROjyBhsS+z8CZDfnWQpJSMHobTSPS5g4M/SCYe7zUjw
TcLCeoiKu7rPWRnWr4+wB7CeMfGCwcDfLqZtbBkOtdh+JhpFAz2weaSUKK0Pfybl
qAj+lug8aJRT7oM6iCsVlgmy4HqMLnXWnOunVmSPlk9orj2XwoSPwLxAwAtcvfaH
szVsrBhQf4TgTM2S0yDpM7xSma8ytSmzJSq0SPly4cpk9+aCEI3oncKKiPo4Zor8
Y/kB+Xj9e1x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lbbC1j+Qa3bb
bP6MvPJwNQzcmRk13NfIRmPVNnGuV/u3gm3c
-----END CERTIFICATE-----
1 change: 1 addition & 0 deletions testing/api/certificates/invalid.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

31 changes: 31 additions & 0 deletions testing/api/certificates/invalidname1234567891234.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
-----BEGIN CERTIFICATE-----
MIIFVzCCAz+gAwIBAgINAgPlk28xsBNJiGuiFzANBgkqhkiG9w0BAQwFADBHMQsw
CQYDVQQGEwJVUzEiMCAGA1UEChMZR29vZ2xlIFRydXN0IFNlcnZpY2VzIExMQzEU
MBIGA1UEAxMLR1RTIFJvb3QgUjEwHhcNMTYwNjIyMDAwMDAwWhcNMzYwNjIyMDAw
MDAwWjBHMQswCQYDVQQGEwJVUzEiMCAGA1UEChMZR29vZ2xlIFRydXN0IFNlcnZp
Y2VzIExMQzEUMBIGA1UEAxMLR1RTIFJvb3QgUjEwggIiMA0GCSqGSIb3DQEBAQUA
A4ICDwAwggIKAoICAQC2EQKLHuOhd5s73L+UPreVp0A8of2C+X0yBoJx9vaMf/vo
27xqLpeXo4xL+Sv2sfnOhB2x+cWX3u+58qPpvBKJXqeqUqv4IyfLpLGcY9vXmX7w
Cl7raKb0xlpHDU0QM+NOsROjyBhsS+z8CZDfnWQpJSMHobTSPS5g4M/SCYe7zUjw
TcLCeoiKu7rPWRnWr4+wB7CeMfGCwcDfLqZtbBkOtdh+JhpFAz2weaSUKK0Pfybl
qAj+lug8aJRT7oM6iCsVlgmy4HqMLnXWnOunVmSPlk9orj2XwoSPwLxAwAtcvfaH
szVsrBhQf4TgTM2S0yDpM7xSma8ytSmzJSq0SPly4cpk9+aCEI3oncKKiPo4Zor8
Y/kB+Xj9e1x3+naH+uzfsQ55lVe0vSbv1gHR6xYKu44LtcXFilWr06zqkUspzBmk
MiVOKvFlRNACzqrOSbTqn3yDsEB750Orp2yjj32JgfpMpf/VjsPOS+C12LOORc92
wO1AK/1TD7Cn1TsNsYqiA94xrcx36m97PtbfkSIS5r762DL8EGMUUXLeXdYWk70p
aDPvOmbsB4om3xPXV2V4J95eSRQAogB/mqghtqmxlbCluQ0WEdrHbEg8QOB+DVrN
VjzRlwW5y0vtOUucxD/SVRNuJLDWcfr0wbrM7Rv1/oFB2ACYPTrIrnqYNxgFlQID
AQABo0IwQDAOBgNVHQ8BAf8EBAMCAYYwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4E
FgQU5K8rJnEaK0gnhS9SZizv8IkTcT4wDQYJKoZIhvcNAQEMBQADggIBAJ+qQibb
C5u+/x6Wki4+omVKapi6Ist9wTrYggoGxval3sBOh2Z5ofmmWJyq+bXmYOfg6LEe
QkEzCzc9zolwFcq1JKjPa7XSQCGYzyI0zzvFIoTgxQ6KfF2I5DUkzps+GlQebtuy
h6f88/qBVRRiClmpIgUxPoLW7ttXNLwzldMXG+gnoot7TiYaelpkttGsN/H9oPM4
7HLwEXWdyzRSjeZ2axfG34arJ45JK3VmgRAhpuo+9K4l/3wV3s6MJT/KYnAK9y8J
ZgfIPxz88NtFMN9iiMG1D53Dn0reWVlHxYciNuaCp+0KueIHoI17eko8cdLiA6Ef
MgfdG+RCzgwARWGAtQsgWSl4vflVy2PFPEz0tv/bal8xa5meLMFrUKTX5hgUvYU/
Z6tGn6D/Qqc6f1zLXbBwHSs09dR2CQzreExZBfMzQsNhFRAbd03OIozUhfJFfbdT
6u9AWpQKXCBfTkBdYiJ23//OYb2MI3jSNwLgjt7RETeJ9r/tSQdirpLsQBqvFAnZ
0E6yove+7u7Y/9waLd64NnHi/Hm3lCXRSHNboTXns5lndcEZOitHTtNCjv0xyBZm
2tIMPNuzjsmhDYAPexZ3FL//2wmUspO8IFgV6dtxQ/PeEMMA3KgqlbbC1j+Qa3bb
bP6MvPJwNQzcmRk13NfIRmPVNnGuV/u3gm3c
-----END CERTIFICATE-----
14 changes: 2 additions & 12 deletions testing/api/profiles/new_profile.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
"name": "New Profile",
"status": "Valid",
"questions": [
{
"question": "What type of device is this?",
"answer": "IoT Gateway"
},
{
"question": "How will this device be used at Google?",
"answer": "Monitoring"
Expand All @@ -18,17 +14,11 @@
"question": "Will the third-party device administrator be able to grant access to authorized Google personnel upon request?",
"answer": "N/A"
},
{
"question": "Are any of the following statements true about your device?",
"answer": [
0
]
},
{
"question": "Which of the following statements are true about this device?",
"answer": [
0
]
]
},
{
"question": "Does the network protocol assure server-to-client identity verification?",
Expand All @@ -38,7 +28,7 @@
"question": "Click the statements that best describe the characteristics of this device.",
"answer": [
0
]
]
},
{
"question": "Are any of the following statements true about this device?",
Expand Down
80 changes: 30 additions & 50 deletions testing/api/profiles/new_profile_2.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,35 @@
"name": "New Profile 2",
"status": "Draft",
"questions": [
{
"question": "What type of device is this?",
"answer": "IoT Gateway"
},
{
"question": "How will this device be used at Google?",
"answer": "Installed in a building"
},
{
"question": "Is this device going to be managed by Google or a third party?",
"answer": "Google"
},
{
"question": "Will the third-party device administrator be able to grant access to authorized Google personnel upon request?",
"answer": "Yes"
},
{
"question": "Are any of the following statements true about your device?",
"answer": [
0,
2
]
},
{
"question": "Which of the following statements are true about this device?",
"answer": [
0,
1,
5
]
},
{
"question": "Does the network protocol assure server-to-client identity verification?",
"answer": "Yes"
},
{
"question": "Click the statements that best describe the characteristics of this device.",
"answer": [
0,
1,
2
]
},
{
"question": "Are any of the following statements true about this device?",
"answer": [
2,
3
]
}
{
"question": "How will this device be used at Google?",
"answer": "Monitoring"
},
{
"question": "Is this device going to be managed by Google or a third party?",
"answer": "Google"
},
{
"question": "Will the third-party device administrator be able to grant access to authorized Google personnel upon request?",
"answer": "N/A"
},
{
"question": "Which of the following statements are true about this device?",
"answer": []
},
{
"question": "Does the network protocol assure server-to-client identity verification?",
"answer": "Yes"
},
{
"question": "Click the statements that best describe the characteristics of this device.",
"answer": []
},
{
"question": "Are any of the following statements true about this device?",
"answer": [
0
]
}
]
}
Loading