File: jwkizable_spec.rb

package info (click to toggle)
ruby-json-jwt 1.6.2-1%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 292 kB
  • sloc: ruby: 2,120; makefile: 3
file content (49 lines) | stat: -rw-r--r-- 1,396 bytes parent folder | download | duplicates (3)
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
require 'spec_helper'

describe JSON::JWK::JWKizable do
  describe '#to_jwk' do
    subject { key.to_jwk }

    shared_examples_for :jwkizable_as_public do
      it { should be_instance_of JSON::JWK }
      it { should include *public_key_attributes.collect(&:to_s) }
      it { should_not include *private_key_attributes.collect(&:to_s) }
    end

    shared_examples_for :jwkizable_as_private do
      it { should be_instance_of JSON::JWK }
      it { should include *public_key_attributes.collect(&:to_s) }
      it { should include *private_key_attributes.collect(&:to_s) }
    end

    describe OpenSSL::PKey::RSA do
      let(:public_key_attributes) { [:kty, :n, :e] }
      let(:private_key_attributes) { [:d, :p, :q] }

      describe :public_key do
        let(:key) { public_key :rsa }
        it_behaves_like :jwkizable_as_public
      end

      describe :private_key do
        let(:key) { private_key :rsa }
        it_behaves_like :jwkizable_as_private
      end
    end

    describe OpenSSL::PKey::EC do
      let(:public_key_attributes) { [:kty, :crv, :x, :y] }
      let(:private_key_attributes) { [:d] }

      describe :public_key do
        let(:key) { public_key :ecdsa }
        it_behaves_like :jwkizable_as_public
      end

      describe :private_key do
        let(:key) { private_key :ecdsa }
        it_behaves_like :jwkizable_as_private
      end
    end
  end
end