summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Estabrook <jestabro@vyos.io>2022-10-23 11:49:08 -0500
committerJohn Estabrook <jestabro@vyos.io>2022-10-25 11:35:26 -0500
commit8ed99cf8662910f8fd28866391591a4fcbfbea47 (patch)
tree2ccec376d7b4f78383a1dce8976898639607cf1a
parentdc37f30a1273c1d3b7949b1d64e60d37da3b9fd4 (diff)
downloadvyos-1x-8ed99cf8662910f8fd28866391591a4fcbfbea47.tar.gz
vyos-1x-8ed99cf8662910f8fd28866391591a4fcbfbea47.zip
graphql: T4574: extend smoketest for token authentication
-rwxr-xr-xsmoketest/scripts/cli/test_service_https.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/smoketest/scripts/cli/test_service_https.py b/smoketest/scripts/cli/test_service_https.py
index 719125f0f..0f4b1393c 100755
--- a/smoketest/scripts/cli/test_service_https.py
+++ b/smoketest/scripts/cli/test_service_https.py
@@ -195,5 +195,49 @@ class TestHTTPSService(VyOSUnitTestSHIM.TestCase):
r = request('POST', graphql_url, verify=False, headers=headers, json={'query': query_no_key})
self.assertEqual(r.status_code, 400)
+ # GraphQL token authentication test: request token; pass in header
+ # of query.
+
+ self.cli_set(base_path + ['api', 'graphql', 'authentication', 'type', 'token'])
+ self.cli_commit()
+
+ mutation = """
+ mutation {
+ AuthToken (data: {username: "vyos", password: "vyos"}) {
+ success
+ errors
+ data {
+ result
+ }
+ }
+ }
+ """
+ r = request('POST', graphql_url, verify=False, headers=headers, json={'query': mutation})
+
+ token = r.json()['data']['AuthToken']['data']['result']['token']
+
+ headers = {'Authorization': f'Bearer {token}'}
+
+ query = """
+ {
+ ShowVersion (data: {}) {
+ success
+ errors
+ op_mode_error {
+ name
+ message
+ vyos_code
+ }
+ data {
+ result
+ }
+ }
+ }
+ """
+
+ r = request('POST', graphql_url, verify=False, headers=headers, json={'query': query})
+ success = r.json()['data']['ShowVersion']['success']
+ self.assertTrue(success)
+
if __name__ == '__main__':
unittest.main(verbosity=2)