~ren/magentasso-rb

ref: 7c97c5c8321e806d4cfc6d90e03abac689d224db magentasso-rb/spec/magentasso_spec.rb -rw-r--r-- 992 bytes
7c97c5c8 — Lauren Jenkinson Add Alpine build job 1 year, 2 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
33
# frozen_string_literal: true

RSpec.describe MagentaSSO do
  it "has a version number" do
    expect(MagentaSSO::VERSION).not_to be nil
  end

  describe "#encode_and_sign" do
    it "encodes the payload JSON" do
      payload, = MagentaSSO.encode_and_sign({ "test" => true }, MagentaSSO::TEST_SECRET)
      decoded_payload = JSON.parse(Base64.urlsafe_decode64(payload))

      expect(decoded_payload).to eq({ "test" => true })
    end

    it "signs the payload" do
      _, signature = MagentaSSO.encode_and_sign({ "test" => true }, MagentaSSO::TEST_SECRET)
      expect(signature).to eq "AHlrP-r0AtZ_zK-uQTUqdBPH85q-Ezu3mDUdlSnndMQ"
    end
  end

  describe "#verify_and_decode" do
    it "verifies the signature and returns the decoded payload" do
      payload = MagentaSSO.verify_and_decode(
        "eyJ0ZXN0Ijp0cnVlfQ",
        "AHlrP-r0AtZ_zK-uQTUqdBPH85q-Ezu3mDUdlSnndMQ",
        MagentaSSO::TEST_SECRET
      )

      expect(payload).to eq({ "test" => true })
    end
  end
end