From 1764ebcfa5eabbdb6b326eb9642e8a14df83cf46 Mon Sep 17 00:00:00 2001 From: petruki <31597636+petruki@users.noreply.github.com> Date: Fri, 31 May 2024 22:21:59 -0700 Subject: [PATCH] Fixes token validation middleware for get domains::slack_route --- ...witcher API (dev).postman_environment.json | 18 +- requests/Switcher API.postman_collection.json | 468 +++++++++++------- src/api-docs/paths/path-slack.js | 2 +- src/routers/slack.js | 2 +- tests/slack.test.js | 15 +- 5 files changed, 317 insertions(+), 188 deletions(-) diff --git a/requests/Switcher API (dev).postman_environment.json b/requests/Switcher API (dev).postman_environment.json index 74e9754..593ae83 100644 --- a/requests/Switcher API (dev).postman_environment.json +++ b/requests/Switcher API (dev).postman_environment.json @@ -9,26 +9,32 @@ }, { "key": "authToken", - "value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI1ZTBlY2UyYjZmNGY5OTRlYWM5MDA3YWQiLCJpYXQiOjE1OTU3MzgyMjgsImV4cCI6MTU5NTczODgyOH0.TEU2wxczfSrxYIbgcanew_GMNSwuph_3RYrPDrXSUAo", + "value": "", "enabled": true }, { "key": "authClientToken", - "value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI1ZTBlY2U2MDZmNGY5OTRlYWM5MDA3YWUiLCJlbnZpcm9ubWVudCI6ImRlZmF1bHQiLCJjb21wb25lbnQiOiJBbmRyb2lkIiwidmMiOiIvbXNYSDdLeVgiLCJpYXQiOjE1OTExNzAwNzgsImV4cCI6MTU5MTE3MDM3OH0.RkkCY_COTfgjEFwxgy6EsSh28JBVuQNNTSqmSwTeFfc", + "value": "", "enabled": true }, { "key": "apiKey", - "value": "$2b$08$7U/KJBVgG.FQtYEKKnbLe.o6p7vBrfHFRgMipZTaokSmVFiduXq/y", + "value": "", "enabled": true }, { "key": "refreshToken", - "value": "$2b$08$upDgjgoNAjHZygvy2kOAsOfFWzsxQpUaICMKO4XWYdxFqWBw3Bv56", + "value": "", + "enabled": true + }, + { + "key": "slackToken", + "value": "", + "type": "default", "enabled": true } ], "_postman_variable_scope": "environment", - "_postman_exported_at": "2020-07-26T05:21:35.636Z", - "_postman_exported_using": "Postman/7.29.1" + "_postman_exported_at": "2024-06-01T05:19:53.623Z", + "_postman_exported_using": "Postman/11.1.14" } \ No newline at end of file diff --git a/requests/Switcher API.postman_collection.json b/requests/Switcher API.postman_collection.json index e464c97..51f9a49 100644 --- a/requests/Switcher API.postman_collection.json +++ b/requests/Switcher API.postman_collection.json @@ -30,9 +30,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -80,9 +80,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -137,9 +137,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -194,9 +194,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -235,8 +235,8 @@ "header": [ { "key": "Content-Type", - "name": "Content-Type", "value": "application/json", + "name": "Content-Type", "type": "text" } ], @@ -286,8 +286,8 @@ "header": [ { "key": "Content-Type", - "name": "Content-Type", "value": "application/json", + "name": "Content-Type", "type": "text" } ], @@ -334,9 +334,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -386,8 +386,8 @@ "header": [ { "key": "Content-Type", - "name": "Content-Type", "value": "application/json", + "name": "Content-Type", "type": "text" } ], @@ -450,8 +450,8 @@ "header": [ { "key": "Authorization", - "type": "text", - "value": "Bearer" + "value": "Bearer", + "type": "text" } ], "url": { @@ -485,8 +485,8 @@ "header": [ { "key": "Authorization", - "type": "text", - "value": "Bearer" + "value": "Bearer", + "type": "text" } ], "url": { @@ -520,13 +520,13 @@ "header": [ { "key": "Authorization", - "type": "text", - "value": "Bearer" + "value": "Bearer", + "type": "text" }, { "key": "Content-Type", - "name": "Content-Type", "value": "application/json", + "name": "Content-Type", "type": "text" } ], @@ -571,8 +571,8 @@ "header": [ { "key": "Authorization", - "type": "text", - "value": "Bearer" + "value": "Bearer", + "type": "text" } ], "url": { @@ -615,13 +615,13 @@ "header": [ { "key": "Authorization", - "type": "text", - "value": "Bearer" + "value": "Bearer", + "type": "text" }, { "key": "Content-Type", - "name": "Content-Type", "value": "application/json", + "name": "Content-Type", "type": "text" } ], @@ -705,9 +705,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -739,9 +739,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -783,9 +783,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -841,9 +841,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -910,9 +910,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -944,9 +944,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -1000,14 +1000,14 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" }, { "key": "", - "type": "text", - "value": "" + "value": "", + "type": "text" } ], "body": { @@ -1045,14 +1045,14 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" }, { "key": "", - "type": "text", - "value": "" + "value": "", + "type": "text" } ], "url": { @@ -1111,9 +1111,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -1169,9 +1169,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -1249,9 +1249,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -1306,9 +1306,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -1362,9 +1362,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -1419,9 +1419,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -1470,9 +1470,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -1521,9 +1521,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -1574,9 +1574,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -1628,9 +1628,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -1690,9 +1690,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -1746,9 +1746,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -1802,9 +1802,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -1858,9 +1858,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -1907,9 +1907,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -1961,9 +1961,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -2020,9 +2020,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -2074,9 +2074,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -2128,9 +2128,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -2182,9 +2182,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -2236,9 +2236,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -2284,9 +2284,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -2332,9 +2332,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -2379,9 +2379,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -2432,9 +2432,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -2494,9 +2494,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -2554,8 +2554,8 @@ "header": [ { "key": "Content-Type", - "name": "Content-Type", "value": "application/json", + "name": "Content-Type", "type": "text" } ], @@ -2588,9 +2588,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -2628,9 +2628,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -2663,9 +2663,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -2698,9 +2698,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -2739,9 +2739,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -2966,9 +2966,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -3000,9 +3000,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -3040,9 +3040,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -3081,9 +3081,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -3374,9 +3374,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -3408,9 +3408,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -3448,9 +3448,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -3489,9 +3489,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -3530,9 +3530,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -3571,9 +3571,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -3612,9 +3612,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -3653,9 +3653,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -3694,9 +3694,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -3735,9 +3735,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -3776,9 +3776,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -3818,9 +3818,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -4003,9 +4003,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -4037,9 +4037,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -4071,9 +4071,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -4111,9 +4111,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -4152,9 +4152,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -4193,9 +4193,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -4234,9 +4234,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -4533,9 +4533,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -4628,9 +4628,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -4779,7 +4779,7 @@ "variable": [ { "key": "domain", - "value": "5e0ece606f4f994eac9007ae" + "value": "" } ] } @@ -4789,6 +4789,16 @@ { "name": "Slack - Ticket History Reset", "request": { + "auth": { + "type": "bearer", + "bearer": [ + { + "key": "token", + "value": "{{slackToken}}", + "type": "string" + } + ] + }, "method": "POST", "header": [], "body": { @@ -4816,13 +4826,23 @@ "response": [] }, { - "name": "Slack - Create Ticket", + "name": "Slack App - Create Ticket", "request": { + "auth": { + "type": "bearer", + "bearer": [ + { + "key": "token", + "value": "{{slackToken}}", + "type": "string" + } + ] + }, "method": "POST", "header": [], "body": { "mode": "raw", - "raw": "{\r\n \"team_id\": \"TEAM_ID\",\r\n \"ticket_content\": {\r\n \"environment\": \"default\",\r\n \"group\": \"Release 1\",\r\n \"switcher\": \"FEATURE02\",\r\n \"status\": false,\r\n \"observations\": \"Activate\"\r\n }\r\n}", + "raw": "{\r\n \"team_id\": \"TEAM_ID\",\r\n \"ticket_content\": {\r\n \"environment\": \"default\",\r\n \"group\": \"Experimental\",\r\n \"switcher\": \"MY_SWITCHER2\",\r\n \"status\": true,\r\n \"observations\": \"Activate\"\r\n }\r\n}", "options": { "raw": { "language": "json" @@ -4845,13 +4865,109 @@ "response": [] }, { - "name": "Slack - Process Ticket", + "name": "Slack App - Validate Ticket", "request": { + "auth": { + "type": "bearer", + "bearer": [ + { + "key": "token", + "value": "{{slackToken}}", + "type": "string" + } + ] + }, "method": "POST", "header": [], "body": { "mode": "raw", - "raw": "{\r\n \"team_id\": \"TEAM_ID\",\r\n \"ticket_id\": \"60b844a27fe6223020777e69\",\r\n \"approved\": false\r\n}", + "raw": "{\r\n \"team_id\": \"TEAM_ID\",\r\n \"ticket_content\": {\r\n \"environment\": \"default\",\r\n \"group\": \"Experimental\",\r\n \"switcher\": \"MY_SWITCHER2\",\r\n \"status\": true,\r\n \"observations\": \"Activate\"\r\n }\r\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{url}}/slack/v1/ticket/validate", + "host": [ + "{{url}}" + ], + "path": [ + "slack", + "v1", + "ticket", + "validate" + ] + } + }, + "response": [] + }, + { + "name": "Slack App - Get Domains By Team Id", + "protocolProfileBehavior": { + "disableBodyPruning": true + }, + "request": { + "auth": { + "type": "bearer", + "bearer": [ + { + "key": "token", + "value": "{{slackToken}}", + "type": "string" + } + ] + }, + "method": "GET", + "header": [], + "body": { + "mode": "raw", + "raw": "", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{url}}/slack/v1/domains?team_id=TEAM_ID", + "host": [ + "{{url}}" + ], + "path": [ + "slack", + "v1", + "domains" + ], + "query": [ + { + "key": "team_id", + "value": "TEAM_ID" + } + ] + } + }, + "response": [] + }, + { + "name": "Slack App - Process Ticket", + "request": { + "auth": { + "type": "bearer", + "bearer": [ + { + "key": "token", + "value": "{{slackToken}}", + "type": "string" + } + ] + }, + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"team_id\": \"TEAM_ID\",\r\n \"ticket_id\": \"665aacd9281e9ee4693db7f9\",\r\n \"approved\": false\r\n}", "options": { "raw": { "language": "json" @@ -4894,8 +5010,8 @@ "header": [ { "key": "Authorization", - "type": "text", "value": "Bearer", + "type": "text", "disabled": true } ], @@ -4941,8 +5057,8 @@ "header": [ { "key": "Authorization", - "type": "text", "value": "Bearer", + "type": "text", "disabled": true } ], @@ -4988,8 +5104,8 @@ "header": [ { "key": "Authorization", - "type": "text", "value": "Bearer", + "type": "text", "disabled": true } ], @@ -5094,9 +5210,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -5155,8 +5271,8 @@ "header": [ { "key": "Content-Type", - "name": "Content-Type", "value": "application/json", + "name": "Content-Type", "type": "text" } ], @@ -5217,9 +5333,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -5284,9 +5400,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -5335,9 +5451,9 @@ "header": [ { "key": "Content-Type", + "value": "application/json", "name": "Content-Type", - "type": "text", - "value": "application/json" + "type": "text" } ], "body": { @@ -5734,8 +5850,8 @@ "header": [ { "key": "Authorization", - "type": "text", "value": "Bearer", + "type": "text", "disabled": true } ], diff --git a/src/api-docs/paths/path-slack.js b/src/api-docs/paths/path-slack.js index f926973..5177737 100644 --- a/src/api-docs/paths/path-slack.js +++ b/src/api-docs/paths/path-slack.js @@ -193,7 +193,7 @@ export default { get: { tags: ['Switcher Slack App'], description: 'Return all domains given a team ID', - security: [{ bearerAuth: [] }], + security: [{ slackAuth: [] }], parameters: [ queryParameter('team_id', 'The Slack team ID', true, 'string') ], diff --git a/src/routers/slack.js b/src/routers/slack.js index 673ead0..f3bb9a2 100644 --- a/src/routers/slack.js +++ b/src/routers/slack.js @@ -191,7 +191,7 @@ router.get('/slack/v1/installation/:domain', auth, [ } }); -router.get('/slack/v1/domains', auth, [ +router.get('/slack/v1/domains', slackAuth, [ query('team_id').exists() ], validate, async (req, res) => { try { diff --git a/tests/slack.test.js b/tests/slack.test.js index c19c103..7fc244a 100644 --- a/tests/slack.test.js +++ b/tests/slack.test.js @@ -93,6 +93,13 @@ describe('Slack Installation', () => { beforeAll(setupDatabase); + test('SLACK_SUITE - Should generate token', async () => { + const token = generateToken('30m'); + const decoded = jwt.verify(token, process.env.SWITCHER_SLACK_JWT_SECRET); + expect(decoded.iss).toBe('Switcher Slack App'); + expect(decoded.sub).toBe('/resource'); + }); + test('SLACK_SUITE - Should save installation', async () => { const response = await request(app) .post('/slack/v1/installation') @@ -512,7 +519,7 @@ describe('Slack Installation', () => { //test const response = await request(app) .get(`/slack/v1/domains?team_id=${teamId}`) - .set('Authorization', `Bearer ${adminMasterAccountToken}`) + .set('Authorization', `Bearer ${generateToken('30s')}`) .send().expect(200); expect(response.body).toMatchObject([ @@ -524,14 +531,14 @@ describe('Slack Installation', () => { test('SLACK_SUITE - Should NOT find Domains by Slack Team Id - Missing param', async () => { await request(app) .get('/slack/v1/domains') - .set('Authorization', `Bearer ${adminMasterAccountToken}`) + .set('Authorization', `Bearer ${generateToken('30s')}`) .send().expect(422); }); test('SLACK_SUITE - Should NOT find Domains by Slack Team Id - Team Id not found', async () => { await request(app) .get('/slack/v1/domains?team_id=NOT_FOUND') - .set('Authorization', `Bearer ${adminMasterAccountToken}`) + .set('Authorization', `Bearer ${generateToken('30s')}`) .send().expect(404); }); @@ -543,7 +550,7 @@ describe('Slack Installation', () => { //test await request(app) .get(`/slack/v1/domains?team_id=${teamId}`) - .set('Authorization', `Bearer ${adminMasterAccountToken}`) + .set('Authorization', `Bearer ${generateToken('30s')}`) .send().expect(404); }); });