|
6 | 6 |
|
7 | 7 | import pytest |
8 | 8 | from codespaces_artifacts_helper_keyring import ( |
9 | | - CredentialProvider, |
| 9 | + ArtifactsHelperCredentialProvider, |
10 | 10 | ) |
11 | | -from codespaces_artifacts_helper_keyring.artifacts_helper_wrapper import ( |
12 | | - CredentialProviderError, |
| 11 | +from codespaces_artifacts_helper_keyring.artifacts_helper_credential_provider import ( |
| 12 | + ArtifactsHelperCredentialProviderError, |
13 | 13 | ) |
14 | 14 |
|
15 | 15 |
|
@@ -38,61 +38,70 @@ def write_script(self, content: str, shebang: str = "#!/usr/bin/env python3"): |
38 | 38 | set_path_executable(self.script_path) |
39 | 39 |
|
40 | 40 | def test_auth_helper_installed_invalid_path(self): |
41 | | - assert not CredentialProvider.resolve_auth_helper_path( |
| 41 | + assert not ArtifactsHelperCredentialProvider.resolve_auth_helper_path( |
42 | 42 | self.tmp_dir / "nonexistent" |
43 | 43 | ) |
44 | | - assert not CredentialProvider.auth_helper_installed( |
| 44 | + assert not ArtifactsHelperCredentialProvider.auth_helper_installed( |
45 | 45 | self.tmp_dir / "nonexistent" |
46 | 46 | ) |
47 | 47 |
|
48 | 48 | def test_auth_helper_installed_and_not_executable(self): |
49 | 49 | self.write_script("pass") |
50 | 50 | set_path_not_executable(self.script_path) |
51 | | - assert not CredentialProvider.resolve_auth_helper_path(self.script_path) |
52 | | - assert not CredentialProvider.auth_helper_installed(self.script_path) |
| 51 | + assert not ArtifactsHelperCredentialProvider.resolve_auth_helper_path( |
| 52 | + self.script_path |
| 53 | + ) |
| 54 | + assert not ArtifactsHelperCredentialProvider.auth_helper_installed( |
| 55 | + self.script_path |
| 56 | + ) |
53 | 57 |
|
54 | 58 | def test_auth_helper_installed_and_executable(self): |
55 | 59 | self.write_script("pass") |
56 | | - assert CredentialProvider.resolve_auth_helper_path(self.script_path) is not None |
57 | | - assert CredentialProvider.auth_helper_installed(self.script_path) |
| 60 | + assert ( |
| 61 | + ArtifactsHelperCredentialProvider.resolve_auth_helper_path(self.script_path) |
| 62 | + is not None |
| 63 | + ) |
| 64 | + assert ArtifactsHelperCredentialProvider.auth_helper_installed(self.script_path) |
58 | 65 |
|
59 | 66 | def test_get_jwt_from_helper(self): |
60 | 67 | raw_jwt_value = "raw_jwt_here._-azAZ09" |
61 | 68 | self.write_script(f"print('{raw_jwt_value}')") |
62 | | - provider = CredentialProvider(self.script_path) |
| 69 | + provider = ArtifactsHelperCredentialProvider(self.script_path) |
63 | 70 | assert provider._get_jwt_from_helper() == raw_jwt_value.strip() |
64 | 71 |
|
65 | 72 | def test_get_jwt_from_helper_not_installed(self): |
66 | | - provider = CredentialProvider() |
| 73 | + provider = ArtifactsHelperCredentialProvider() |
67 | 74 | with pytest.raises( |
68 | | - CredentialProviderError, match="No authentication tool found" |
| 75 | + ArtifactsHelperCredentialProviderError, match="No authentication tool found" |
69 | 76 | ): |
70 | 77 | provider._get_jwt_from_helper() |
71 | 78 |
|
72 | 79 | def test_get_credentials_from_jwt(self): |
73 | | - provider = CredentialProvider() |
| 80 | + provider = ArtifactsHelperCredentialProvider() |
74 | 81 | creds = provider._get_credentials_from_jwt(self.TEST_JWT) |
75 | 82 | assert creds.username == self.TEST_JWT_USERNAME |
76 | 83 | assert creds.password == self.TEST_JWT |
77 | 84 |
|
78 | 85 | def test_get_credentials(self): |
79 | 86 | self.write_script(f"print('{self.TEST_JWT}')") |
80 | | - provider = CredentialProvider(self.script_path) |
| 87 | + provider = ArtifactsHelperCredentialProvider(self.script_path) |
81 | 88 | creds = provider.get_credentials(self.SUPPORTED_HOST) |
82 | 89 | assert creds.username == self.TEST_JWT_USERNAME |
83 | 90 | assert creds.password == self.TEST_JWT |
84 | 91 |
|
85 | 92 | def test_get_credentials_invalid_jwt(self): |
86 | 93 | self.write_script("print('invalid jwt')") |
87 | | - provider = CredentialProvider(self.script_path) |
88 | | - with pytest.raises(CredentialProviderError, match="Failed to decode JWT:"): |
| 94 | + provider = ArtifactsHelperCredentialProvider(self.script_path) |
| 95 | + with pytest.raises( |
| 96 | + ArtifactsHelperCredentialProviderError, match="Failed to decode JWT:" |
| 97 | + ): |
89 | 98 | provider.get_credentials(self.SUPPORTED_HOST) |
90 | 99 |
|
91 | 100 | def test_get_crendentials_helper_non_zero_exit(self): |
92 | 101 | self.write_script("exit(1)") |
93 | | - provider = CredentialProvider(self.script_path) |
| 102 | + provider = ArtifactsHelperCredentialProvider(self.script_path) |
94 | 103 | with pytest.raises( |
95 | | - CredentialProviderError, |
| 104 | + ArtifactsHelperCredentialProviderError, |
96 | 105 | match=f"Process .*{self.script_name}.* exited with code 1", |
97 | 106 | ): |
98 | 107 | provider.get_credentials(self.SUPPORTED_HOST) |
|
0 commit comments