-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change encode secret string resolver to mutation (#615)
- Loading branch information
1 parent
1787236
commit 8ab87fd
Showing
14 changed files
with
119 additions
and
66 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
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from django.test import TransactionTestCase | ||
from shared.encryption.yaml_secret import yaml_secret_encryptor | ||
|
||
from codecov_auth.tests.factories import OwnerFactory | ||
from core.tests.factories import RepositoryFactory | ||
from graphql_api.tests.helper import GraphQLTestHelper | ||
|
||
query = """ | ||
mutation($input: EncodeSecretStringInput!) { | ||
encodeSecretString(input: $input) { | ||
value | ||
error { | ||
__typename | ||
... on ResolverError { | ||
message | ||
} | ||
} | ||
} | ||
} | ||
""" | ||
|
||
|
||
class TestEncodeSecretString(TransactionTestCase, GraphQLTestHelper): | ||
def _request(self): | ||
data = self.gql_request( | ||
query, | ||
owner=self.org, | ||
variables={"input": {"repoName": "test-repo", "value": "token-1"}}, | ||
) | ||
return data["encodeSecretString"]["value"] | ||
|
||
def setUp(self): | ||
self.org = OwnerFactory(username="test-org") | ||
self.repo = RepositoryFactory( | ||
name="test-repo", | ||
author=self.org, | ||
private=True, | ||
) | ||
self.owner = OwnerFactory(permission=[self.repo.pk]) | ||
|
||
def test_encoded_secret_string(self): | ||
res = self._request() | ||
check_encryptor = yaml_secret_encryptor | ||
assert "token-1" in check_encryptor.decode(res[7:]) |
40 changes: 0 additions & 40 deletions
40
graphql_api/tests/test_repository_encoded_secret_string.py
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
input EncodeSecretStringInput { | ||
repoName: String! | ||
value: String! | ||
} |
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
10 changes: 10 additions & 0 deletions
10
graphql_api/types/mutation/encode_secret_string/__init__.py
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from graphql_api.helpers.ariadne import ariadne_load_local_graphql | ||
|
||
from .encode_secret_string import ( | ||
error_encode_secret_string, | ||
resolve_encode_secret_string, | ||
) | ||
|
||
gql_encode_secret_string = ariadne_load_local_graphql( | ||
__file__, "encode_secret_string.graphql" | ||
) |
6 changes: 6 additions & 0 deletions
6
graphql_api/types/mutation/encode_secret_string/encode_secret_string.graphql
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
union EncodeSecretStringError = ValidationError | UnauthenticatedError | ||
|
||
type EncodeSecretStringPayload { | ||
error: EncodeSecretStringError | ||
value: String | ||
} |
24 changes: 24 additions & 0 deletions
24
graphql_api/types/mutation/encode_secret_string/encode_secret_string.py
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from ariadne import UnionType | ||
|
||
from graphql_api.helpers.mutation import ( | ||
require_authenticated, | ||
resolve_union_error_type, | ||
wrap_error_handling_mutation, | ||
) | ||
|
||
|
||
@wrap_error_handling_mutation | ||
@require_authenticated | ||
async def resolve_encode_secret_string(_, info, input) -> None: | ||
command = info.context["executor"].get_command("repository") | ||
repo_name = input.get("repoName") | ||
value = input.get("value") | ||
current_owner = info.context["request"].current_owner | ||
value = command.encode_secret_string( | ||
repo_name=repo_name, owner=current_owner, value=value | ||
) | ||
return {"value": value} | ||
|
||
|
||
error_encode_secret_string = UnionType("EraseRepositoryError") | ||
error_encode_secret_string.type_resolver(resolve_union_error_type) |
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