diff options
author | Daniil Baturin <daniil@vyos.io> | 2022-07-25 10:34:17 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-25 10:34:17 +0100 |
commit | 3337aedd5f7ff48bfad051d760023a188fdace70 (patch) | |
tree | 3dc5b5c22444430a74f8d0f8a8ed54415a8ccd47 /smoketest | |
parent | e1e9f690d3eb4cd03aba118558fffd5b6b2920c8 (diff) | |
parent | f9d6f089014007193996e51757f72a8bf7ec78b9 (diff) | |
download | vyos-1x-3337aedd5f7ff48bfad051d760023a188fdace70.tar.gz vyos-1x-3337aedd5f7ff48bfad051d760023a188fdace70.zip |
Merge pull request #1431 from jestabro/gql-dev
graphql: T4567: Merge experimental branch of GraphQL development
Diffstat (limited to 'smoketest')
-rwxr-xr-x | smoketest/scripts/cli/test_service_https.py | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/smoketest/scripts/cli/test_service_https.py b/smoketest/scripts/cli/test_service_https.py index 71fb3e177..72c1d4e43 100755 --- a/smoketest/scripts/cli/test_service_https.py +++ b/smoketest/scripts/cli/test_service_https.py @@ -138,5 +138,62 @@ class TestHTTPSService(VyOSUnitTestSHIM.TestCase): # Must get HTTP code 401 on missing key (Unauthorized) self.assertEqual(r.status_code, 401) + # GraphQL auth test: a missing key will return status code 400, as + # 'key' is a non-nullable field in the schema; an incorrect key is + # caught by the resolver, and returns success 'False', so one must + # check the return value. + + self.cli_set(base_path + ['api', 'gql']) + self.cli_commit() + + gql_url = f'https://{address}/graphql' + + query_valid_key = f""" + {{ + SystemStatus (data: {{key: "{key}"}}) {{ + success + errors + data {{ + result + }} + }} + }} + """ + + r = request('POST', gql_url, verify=False, headers=headers, json={'query': query_valid_key}) + success = r.json()['data']['SystemStatus']['success'] + self.assertTrue(success) + + query_invalid_key = """ + { + SystemStatus (data: {key: "invalid"}) { + success + errors + data { + result + } + } + } + """ + + r = request('POST', gql_url, verify=False, headers=headers, json={'query': query_invalid_key}) + success = r.json()['data']['SystemStatus']['success'] + self.assertFalse(success) + + query_no_key = """ + { + SystemStatus (data: {}) { + success + errors + data { + result + } + } + } + """ + + r = request('POST', gql_url, verify=False, headers=headers, json={'query': query_no_key}) + self.assertEqual(r.status_code, 400) + if __name__ == '__main__': unittest.main(verbosity=2) |