Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yasunariw committed Dec 23, 2020
1 parent 19953a5 commit cd9f648
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 2 deletions.
16 changes: 14 additions & 2 deletions test/dune
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(executable
(name test)
(executables
(names test slack_oauth_test)
(libraries lib base base.caml devkit devkit.core extlib lwt.unix stdio
yojson)
(preprocess
Expand All @@ -21,3 +21,15 @@
(alias runtest)
(action
(diff slack_payloads.expected slack_payloads.out)))

(rule
(deps notabot.json secrets.json)
(action
(with-stdout-to
slack_oauth.out
(run ./slack_oauth_test.exe))))

(rule
(alias runtest)
(action
(diff slack_oauth.expected slack_oauth.out)))
13 changes: 13 additions & 0 deletions test/slack_oauth.expected
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 ====
58 changes: 58 additions & 0 deletions test/slack_oauth_test.ml
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

0 comments on commit cd9f648

Please sign in to comment.