-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
### Feature or Bugfix <!-- please choose --> - Feature ### Detail - Add integration tests for `vote` module - Fix Vote creation by username ### Relates - #1220 ### Security Please answer the questions below briefly where applicable, or write `N/A`. Based on [OWASP 10](https://owasp.org/Top10/en/). - Does this PR introduce or modify any input fields or queries - this includes fetching data from storage outside the application (e.g. a database, an S3 bucket)? - Is the input sanitized? - What precautions are you taking before deserializing the data you consume? - Is injection prevented by parametrizing queries? - Have you ensured no `eval` or similar functions are used? - Does this PR introduce any functionality or component that requires authorization? - How have you ensured it respects the existing AuthN/AuthZ mechanisms? - Are you logging failed auth attempts? - Are you using or adding any cryptographic features? - Do you use a standard proven implementations? - Are the used keys controlled by the customer? Where are they stored? - Are you introducing any new policies/roles/users? - Have you used the least-privilege principle? How? By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
- Loading branch information
1 parent
cb909e9
commit 0931949
Showing
4 changed files
with
119 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import pytest | ||
from integration_tests.modules.vote.queries import upvote, get_vote | ||
|
||
|
||
S3_DATASET_TARGET_TYPE = 'dataset' | ||
|
||
|
||
@pytest.fixture(scope='session') | ||
def vote1(client1, session_s3_dataset1): | ||
upvote(client1, session_s3_dataset1.datasetUri, S3_DATASET_TARGET_TYPE, True) | ||
yield get_vote(client1, session_s3_dataset1.datasetUri, S3_DATASET_TARGET_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# TODO: This file will be replaced by using the SDK directly | ||
|
||
|
||
def upvote(client, uri, target_type, vote): | ||
query = { | ||
'operationName': 'upVote', | ||
'variables': {'input': {'targetUri': uri, 'targetType': target_type, 'upvote': vote}}, | ||
'query': """ | ||
mutation upVote($input:VoteInput!){ | ||
upVote(input:$input){ | ||
voteUri | ||
targetUri | ||
targetType | ||
upvote | ||
} | ||
} | ||
""", | ||
} | ||
|
||
response = client.query(query=query) | ||
return response.data.upVote | ||
|
||
|
||
def count_upvotes(client, uri, target_type): | ||
query = { | ||
'operationName': 'countUpVotes', | ||
'variables': {'targetUri': uri, 'targetType': target_type}, | ||
'query': """ | ||
query countUpVotes($targetUri:String!, $targetType:String!){ | ||
countUpVotes(targetUri:$targetUri, targetType:$targetType) | ||
} | ||
""", | ||
} | ||
response = client.query(query=query) | ||
return response.data.countUpVotes | ||
|
||
|
||
def get_vote(client, uri, target_type): | ||
query = { | ||
'operationName': 'getVote', | ||
'variables': {'targetUri': uri, 'targetType': target_type}, | ||
'query': """ | ||
query getVote($targetUri:String!, $targetType:String!){ | ||
getVote(targetUri:$targetUri, targetType:$targetType){ | ||
upvote | ||
voteUri | ||
targetUri | ||
targetType | ||
} | ||
} | ||
""", | ||
} | ||
response = client.query(query=query) | ||
print(response.data.getVote) | ||
return response.data.getVote |
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,51 @@ | ||
from assertpy import assert_that | ||
|
||
from integration_tests.errors import GqlError | ||
|
||
from integration_tests.modules.vote.queries import upvote, count_upvotes, get_vote | ||
from integration_tests.modules.vote.conftest import S3_DATASET_TARGET_TYPE | ||
|
||
|
||
def test_upvote(client1, vote1): | ||
assert_that(vote1).is_not_none() | ||
assert_that(vote1.voteUri).is_not_none() | ||
assert_that(vote1.upvote).is_true() | ||
|
||
|
||
def test_upvote_invalid(client1, vote1, session_s3_dataset1): | ||
assert_that(upvote).raises(GqlError).when_called_with(client1, session_s3_dataset1.datasetUri, None, True).contains( | ||
'targetType', 'not to be None' | ||
) | ||
assert_that(upvote).raises(GqlError).when_called_with(client1, None, S3_DATASET_TARGET_TYPE, True).contains( | ||
'targetUri', 'not to be None' | ||
) | ||
|
||
|
||
def test_get_vote_invalid(client1, vote1, session_s3_dataset1): | ||
assert_that(get_vote).raises(GqlError).when_called_with(client1, session_s3_dataset1.datasetUri, None).contains( | ||
'targetType', 'must not be null' | ||
) | ||
assert_that(get_vote).raises(GqlError).when_called_with(client1, None, S3_DATASET_TARGET_TYPE).contains( | ||
'targetUri', 'must not be null' | ||
) | ||
|
||
|
||
def test_count_upvote_invalid(client1, vote1, session_s3_dataset1): | ||
assert_that(count_upvotes).raises(GqlError).when_called_with( | ||
client1, session_s3_dataset1.datasetUri, None | ||
).contains('targetType', 'must not be null') | ||
assert_that(count_upvotes).raises(GqlError).when_called_with(client1, None, S3_DATASET_TARGET_TYPE).contains( | ||
'targetUri', 'must not be null' | ||
) | ||
|
||
|
||
def test_count_votes(client2, vote1, session_s3_dataset1): | ||
count = count_upvotes(client2, session_s3_dataset1.datasetUri, S3_DATASET_TARGET_TYPE) | ||
|
||
# Assert incremeent by 1 | ||
upvote(client2, session_s3_dataset1.datasetUri, S3_DATASET_TARGET_TYPE, True) | ||
assert_that(count_upvotes(client2, session_s3_dataset1.datasetUri, S3_DATASET_TARGET_TYPE)).is_equal_to(count + 1) | ||
|
||
# Assert decrement by 1 | ||
upvote(client2, session_s3_dataset1.datasetUri, S3_DATASET_TARGET_TYPE, False) | ||
assert_that(count_upvotes(client2, session_s3_dataset1.datasetUri, S3_DATASET_TARGET_TYPE)).is_equal_to(count) |