summaryrefslogtreecommitdiff
path: root/smoketest
diff options
context:
space:
mode:
authorJohn Estabrook <jestabro@vyos.io>2022-10-25 12:08:42 -0500
committerGitHub <noreply@github.com>2022-10-25 12:08:42 -0500
commit1265b15ffc8baa05177c707f30205d70528c5dc6 (patch)
tree8cb9715666250f8599147d066bd93a9a06df4962 /smoketest
parentec82d60828500a56b6fe8357970bf839053ac0af (diff)
parent3db5ba8ef354d80f080cc1baacf33d77ccbb6222 (diff)
downloadvyos-1x-1265b15ffc8baa05177c707f30205d70528c5dc6.tar.gz
vyos-1x-1265b15ffc8baa05177c707f30205d70528c5dc6.zip
Merge pull request #1613 from jestabro/graphql-hybrid-auth
graphql: T4574: add JWT token authentication
Diffstat (limited to 'smoketest')
-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)