summaryrefslogtreecommitdiff
path: root/deps/rabbitmq_auth_backend_oauth2/test/rabbit_auth_backend_oauth2_test_util.erl
diff options
context:
space:
mode:
authorMichael Klishin <michael@clojurewerkz.org>2019-07-02 12:15:17 +0200
committerMichael Klishin <michael@clojurewerkz.org>2019-07-02 12:15:17 +0200
commit16f732898679727fc06397f93e17d5d864044614 (patch)
treeb66ae68d2aa40f9d906bad186f98b34f20ed68b4 /deps/rabbitmq_auth_backend_oauth2/test/rabbit_auth_backend_oauth2_test_util.erl
parentd44e4bce59a01cdd7bd7432ebf2790f1ef3af642 (diff)
downloadrabbitmq-server-git-16f732898679727fc06397f93e17d5d864044614.tar.gz
Integration suite: correctly compute expiration
it should be in seconds.
Diffstat (limited to 'deps/rabbitmq_auth_backend_oauth2/test/rabbit_auth_backend_oauth2_test_util.erl')
-rw-r--r--deps/rabbitmq_auth_backend_oauth2/test/rabbit_auth_backend_oauth2_test_util.erl15
1 files changed, 8 insertions, 7 deletions
diff --git a/deps/rabbitmq_auth_backend_oauth2/test/rabbit_auth_backend_oauth2_test_util.erl b/deps/rabbitmq_auth_backend_oauth2/test/rabbit_auth_backend_oauth2_test_util.erl
index b26413d630..956ee56d07 100644
--- a/deps/rabbitmq_auth_backend_oauth2/test/rabbit_auth_backend_oauth2_test_util.erl
+++ b/deps/rabbitmq_auth_backend_oauth2/test/rabbit_auth_backend_oauth2_test_util.erl
@@ -2,7 +2,7 @@
-compile(export_all).
--define(EXPIRATION_TIME, 2000).
+-define(DEFAULT_EXPIRATION_IN_SECONDS, 2).
%%
%% API
@@ -47,15 +47,15 @@ full_permission_scopes() ->
<<"rabbitmq.read:*/*">>].
expirable_token() ->
- TokenPayload = fixture_token(),
- TokenPayload#{<<"exp">> := os:system_time(seconds) + timer:seconds(?EXPIRATION_TIME)}.
+ expirable_token(?DEFAULT_EXPIRATION_IN_SECONDS).
expirable_token(Seconds) ->
TokenPayload = fixture_token(),
- TokenPayload#{<<"exp">> := os:system_time(seconds) + timer:seconds(Seconds)}.
+ %% expiration is a timestamp with precision in seconds
+ TokenPayload#{<<"exp">> := os:system_time(seconds) + Seconds}.
wait_for_token_to_expire() ->
- timer:sleep(?EXPIRATION_TIME).
+ timer:sleep(timer:seconds(?DEFAULT_EXPIRATION_IN_SECONDS)).
wait_for_token_to_expire(DurationInMs) ->
timer:sleep(DurationInMs).
@@ -64,12 +64,13 @@ expired_token() ->
expired_token_with_scopes(full_permission_scopes()).
expired_token_with_scopes(Scopes) ->
- token_with_scopes_and_expiration(Scopes, os:system_time(seconds) - timer:seconds(10)).
+ token_with_scopes_and_expiration(Scopes, os:system_time(seconds) - 10).
fixture_token_with_scopes(Scopes) ->
- token_with_scopes_and_expiration(Scopes, os:system_time(seconds) + timer:seconds(10)).
+ token_with_scopes_and_expiration(Scopes, os:system_time(seconds) + 10).
token_with_scopes_and_expiration(Scopes, Expiration) ->
+ %% expiration is a timestamp with precision in seconds
#{<<"exp">> => Expiration,
<<"kid">> => <<"token-key">>,
<<"iss">> => <<"unit_test">>,