summaryrefslogtreecommitdiffstats
path: root/spec/helpers_spec.cr
diff options
context:
space:
mode:
authorOmar Roth <omarroth@hotmail.com>2019-04-10 16:58:46 -0500
committerOmar Roth <omarroth@hotmail.com>2019-04-10 16:58:46 -0500
commitaad0f90a9daf4219b06e874d23efc923bc9b09b6 (patch)
treef6b754e39a6c1f0a06120f70e0945f29db16a7fd /spec/helpers_spec.cr
parent5dc45c35e64c1e5882e0c01287b36ec88dff70a7 (diff)
downloadinvidious-aad0f90a9daf4219b06e874d23efc923bc9b09b6.tar.gz
invidious-aad0f90a9daf4219b06e874d23efc923bc9b09b6.tar.bz2
invidious-aad0f90a9daf4219b06e874d23efc923bc9b09b6.zip
Add 'sign_token'
Diffstat (limited to 'spec/helpers_spec.cr')
-rw-r--r--spec/helpers_spec.cr24
1 files changed, 24 insertions, 0 deletions
diff --git a/spec/helpers_spec.cr b/spec/helpers_spec.cr
index 307e52d2..215ffc76 100644
--- a/spec/helpers_spec.cr
+++ b/spec/helpers_spec.cr
@@ -1,4 +1,5 @@
require "kemal"
+require "openssl/hmac"
require "pg"
require "spec"
require "yaml"
@@ -81,4 +82,27 @@ describe "Helpers" do
produce_comment_reply_continuation("_cE8xSu6swE", "UC1AZY74-dGVPe6bfxFwwEMg", "UgyBUaRGHB9Jmt1dsUZ4AaABAg").should eq("EiYSC19jRTh4U3U2c3dFwAEByAEB4AEBogINKP___________wFAABgGMk0aSxIaVWd5QlVhUkdIQjlKbXQxZHNVWjRBYUFCQWciAggAKhhVQzFBWlk3NC1kR1ZQZTZiZnhGd3dFTWcyC19jRTh4U3U2c3dFQAFICg%3D%3D")
end
end
+
+ describe "#sign_token" do
+ it "correctly signs a given hash" do
+ token = {
+ "session" => "v1:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
+ "expires" => 1554680038,
+ "scopes" => [
+ ":notifications",
+ ":subscriptions/*",
+ "GET:tokens*",
+ ],
+ "signature" => "f//2hS20th8pALF305PJFK+D2aVtvefNnQheILHD2vU=",
+ }
+ sign_token("SECRET_KEY", token).should eq(token["signature"])
+
+ token = {
+ "session" => "v1:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
+ "scopes" => [":notifications", "POST:subscriptions/*"],
+ "signature" => "fNvXoT0MRAL9eE6lTE33CEg8HitYJDOL9a22rSN2Ihg=",
+ }
+ sign_token("SECRET_KEY", token).should eq(token["signature"])
+ end
+ end
end