-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Additional unit-tests and unit-test adjustment (#499)
Refactors unit-tests to use a common set of environment variables and adds a bunch of missing MQTT311 and MQTT5 connection-related unit-tests.
- Loading branch information
1 parent
9f259ec
commit 4716c95
Showing
13 changed files
with
3,012 additions
and
991 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,9 @@ | ||
import Builder | ||
import json | ||
import os | ||
import re | ||
import subprocess | ||
import sys | ||
import tempfile | ||
|
||
|
||
class CrtCiPrep(Builder.Action): | ||
def _write_environment_script_secret_to_env(self, env, secret_name): | ||
mqtt5_ci_environment_script = env.shell.get_secret(secret_name) | ||
env_line = re.compile('^export\s+(\w+)=(.+)') | ||
|
||
lines = mqtt5_ci_environment_script.splitlines() | ||
for line in lines: | ||
env_pair_match = env_line.match(line) | ||
if env_pair_match.group(1) and env_pair_match.group(2): | ||
env.shell.setenv(env_pair_match.group(1), env_pair_match.group(2), quiet=True) | ||
|
||
def _write_secret_to_temp_file(self, env, secret_name): | ||
secret_value = env.shell.get_secret(secret_name) | ||
|
||
fd, filename = tempfile.mkstemp() | ||
os.write(fd, str.encode(secret_value)) | ||
os.close(fd) | ||
|
||
return filename | ||
|
||
def _write_s3_to_temp_file(self, env, s3_file): | ||
try: | ||
tmp_file = tempfile.NamedTemporaryFile(delete=False) | ||
tmp_file.flush() | ||
tmp_s3_filepath = tmp_file.name | ||
cmd = ['aws', '--region', 'us-east-1', 's3', 'cp', | ||
s3_file, tmp_s3_filepath] | ||
env.shell.exec(*cmd, check=True, quiet=True) | ||
return tmp_s3_filepath | ||
except: | ||
print (f"ERROR: Could not get S3 file from URL {s3_file}!") | ||
raise RuntimeError("Could not get S3 file from URL") | ||
|
||
|
||
def run(self, env): | ||
env.shell.setenv("AWS_TESTING_COGNITO_IDENTITY", env.shell.get_secret("aws-c-auth-testing/cognito-identity")) | ||
env.shell.setenv("AWS_TESTING_STS_ROLE_ARN", env.shell.get_secret("aws-c-auth-testing/sts-role-arn")) | ||
|
||
# Unfortunately, we can't use NamedTemporaryFile and a with-block because NamedTemporaryFile is not readable | ||
# on Windows. | ||
self._write_environment_script_secret_to_env(env, "mqtt5-testing/github-ci-environment") | ||
|
||
cert_file_name = self._write_secret_to_temp_file(env, "unit-test/certificate") | ||
key_file_name = self._write_secret_to_temp_file(env, "unit-test/privatekey") | ||
|
||
env.shell.setenv("AWS_TEST_MQTT5_IOT_CORE_CERTIFICATE_PATH", cert_file_name, quiet=True) | ||
env.shell.setenv("AWS_TEST_MQTT5_IOT_CORE_KEY_PATH", key_file_name, quiet=True) | ||
|
||
# PKCS12 setup (MacOS only) | ||
if (sys.platform == "darwin"): | ||
pkcs12_file_name = self._write_s3_to_temp_file(env, "s3://aws-crt-test-stuff/unit-test-key-pkcs12.pem") | ||
env.shell.setenv("AWS_TEST_MQTT311_IOT_CORE_PKCS12_KEY", pkcs12_file_name) | ||
env.shell.setenv("AWS_TEST_MQTT311_IOT_CORE_PKCS12_KEY_PASSWORD", "PKCS12_KEY_PASSWORD") | ||
|
||
actions = [] | ||
|
||
actions = [ | ||
Builder.SetupCrossCICrtEnvironment() | ||
] | ||
return Builder.Script(actions, name='crt-ci-prep') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.