-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
85 additions
and
2 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,13 @@ | ||
===== slack oauth: success, valid params ==== | ||
will generate token | ||
===== slack oauth: success, no signing key ==== | ||
will generate token | ||
===== slack oauth: success, with state ==== | ||
will generate token | ||
===== slack oauth: no-op, token exists ==== | ||
===== slack oauth: failure, no state arg ==== | ||
===== slack oauth: failure, bad state arg ==== | ||
===== slack oauth: failure, no code arg ==== | ||
===== slack oauth: failure, bad timestamp ==== | ||
===== slack oauth: failure, no signature ==== | ||
===== slack oauth: failure, no timestamp ==== |
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,58 @@ | ||
open Base | ||
open Lib | ||
module Action = Action.Action (Api_local.Github) (Api_local.Slack) | ||
|
||
let signing_key = "8f742231b10e8888abcd99yyyzzz85a5" | ||
|
||
let sig_header = "x-slack-signature", "v0=abb033014f155dcde840b8dc150b1fb12433b8f8233ffc2853be34e151bad9e8" | ||
|
||
let ts_valid = "x-slack-request-timestamp", "1531420618" | ||
|
||
let ts_invalid = "x-slack-request-timestamp", "5000000000" | ||
|
||
let arg_code = "code", "1591663521684.1613458437648.4a18cf683e541ff9d8fd75075181cac49c7acae9431d7e4ffd424ce1ca8d2543" | ||
|
||
let arg_state = "state", "foo" | ||
|
||
let arg_state_bad = "state", "bar" | ||
|
||
let secrets_default : Config_t.secrets = | ||
{ | ||
gh_token = None; | ||
gh_hook_token = None; | ||
slack_client_id = ""; | ||
slack_client_secret = ""; | ||
slack_oauth_state = None; | ||
slack_signing_secret = None; | ||
slack_access_token = None; | ||
} | ||
|
||
let secrets_with_key = { secrets_default with slack_signing_secret = Some signing_key } | ||
|
||
let secrets_with_state = { secrets_default with slack_oauth_state = Some "foo" } | ||
|
||
let secrets_with_token = { secrets_default with slack_access_token = Some "123" } | ||
|
||
(* name, args, headers, body *) | ||
let tests = | ||
[ | ||
"success, valid params", [ arg_code ], [ sig_header; ts_valid ], "text=hello", secrets_with_key; | ||
"success, no signing key", [ arg_code ], [ sig_header; ts_valid ], "text=hello", secrets_default; | ||
"success, with state", [ arg_code; arg_state ], [ sig_header; ts_valid ], "text=hello", secrets_with_state; | ||
"no-op, token exists", [ arg_code ], [ sig_header; ts_valid ], "text=hello", secrets_with_token; | ||
"failure, no state arg", [ arg_code ], [ sig_header; ts_valid ], "text=hello", secrets_with_state; | ||
"failure, bad state arg", [ arg_code; arg_state_bad ], [ sig_header; ts_valid ], "text=hello", secrets_with_state; | ||
"failure, no code arg", [], [ sig_header; ts_valid ], "text=hello", secrets_with_key; | ||
"failure, bad timestamp", [ arg_code ], [ sig_header; ts_invalid ], "text=hello", secrets_with_key; | ||
"failure, no signature", [ arg_code ], [ ts_valid ], "text=hello", secrets_with_key; | ||
"failure, no timestamp", [ arg_code ], [ sig_header ], "text=hello", secrets_with_key; | ||
] | ||
|
||
let process (ctx : Context.t) (name, args, headers, body, secrets) = | ||
ctx.secrets <- Some secrets; | ||
Stdio.printf "===== slack oauth: %s ====\n" name; | ||
Action.process_slack_oauth ctx args headers body | ||
|
||
let () = | ||
let ctx = Context.make () in | ||
Lwt_main.run @@ Lwt_list.iter_s (process ctx) tests |