def test_overwriting_keys(tmp_path): key_file = tmp_path / 'dev.key.pem' certificate_file = tmp_path / 'dev.cert.der' generate_credentials(key_file=key_file, certificate_file=certificate_file, do_overwrite=False, cred_valid_time=8) key_digest = digest_file(key_file) cert_digest = digest_file(certificate_file) generate_credentials(key_file=key_file, certificate_file=certificate_file, do_overwrite=True, cred_valid_time=8) assert key_digest != digest_file(key_file) assert cert_digest != digest_file(certificate_file)
def test_cli(tmp_path): c_source = tmp_path / 'update_default_resources.c' cache_dir = tmp_path / defaults.BASE_PATH.as_posix() dev_cfg = cache_dir / defaults.DEV_CFG cert = cache_dir / defaults.UPDATE_PUBLIC_KEY_CERT key = cache_dir / defaults.UPDATE_PRIVATE_KEY api_cfg = cache_dir / defaults.CLOUD_CFG dummy_access_key = '456321789541515' dummy_api_url = 'https://i.am.tired.of.writing.tests.com' cmd = ['--debug', 'init'] with conftest.working_directory(tmp_path): assert 0 == dev_tool.entry_point(cmd) assert not api_cfg.is_file() dev_cfg_digest = digest_file(dev_cfg) c_source_digest = digest_file(c_source) cert_digest = digest_file(cert) key_digest = digest_file(key) cmd = [ 'init', '--access-key', dummy_access_key, '--api-url', dummy_api_url ] with conftest.working_directory(tmp_path): assert 0 == dev_tool.entry_point( cmd + ['--api-url', 'https://some.url.pelion.com']) assert c_source_digest != digest_file(c_source) assert cert_digest != digest_file(cert) assert key_digest != digest_file(key) assert dev_cfg_digest != digest_file(dev_cfg) assert api_cfg.is_file() with conftest.working_directory(tmp_path): assert 0 == dev_tool.entry_point(cmd + ['--force']) assert c_source_digest != digest_file(c_source) assert cert_digest != digest_file(cert) assert key_digest != digest_file(key) assert dev_cfg_digest != digest_file(dev_cfg) with api_cfg.open('rb') as fh: api_cfg_data = yaml.safe_load(fh) assert dummy_access_key == api_cfg_data['access_key'] assert dummy_api_url == api_cfg_data['host']