~ren/magentasso-rb

ref: 4751491c21c5d31117ad9da65ba9f2e9fc454290 magentasso-rb/spec/magentasso_request_spec.rb -rw-r--r-- 835 bytes
4751491c — Lauren Jenkinson Keep dependencies in gemspec in alphabetical order 1 year, 3 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# frozen_string_literal: true

RSpec.describe MagentaSSO::Request do
  it "signs a request" do
    request = MagentaSSO::Request.new(
      "test",
      MagentaSSO::TEST_SECRET,
      123_456,
      ["profile"],
      "https://example.com/sso"
    )

    _, signature = request.sign
    expect(signature).to eq "QrPlvDbAZk0aH46Wl2qbGWpBL1EqU8H6QTgemxdR-kM"
  end

  it "verifies a signed request" do
    payload =
      "eyJjbGllbnRfaWQiOiJ0ZXN0Iiwibm9uY2UiOjEyMzQ1Niwic2NvcGVzIjpbInByb" \
      "2ZpbGUiXSwiY2FsbGJhY2tfdXJsIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9zc28ifQ"
    signature = "QrPlvDbAZk0aH46Wl2qbGWpBL1EqU8H6QTgemxdR-kM"

    request = MagentaSSO::Request.verify(
      payload,
      signature,
      MagentaSSO::TEST_SECRET
    )

    expect(request.scopes).to eq(["profile"])
    expect(request.nonce).to eq 123_456
  end
end