Skip to content
This repository has been archived by the owner on Jan 1, 2024. It is now read-only.

Commit

Permalink
Merge 3909a8e into 49a2fa7
Browse files Browse the repository at this point in the history
  • Loading branch information
petergoldstein committed Feb 2, 2014
2 parents 49a2fa7 + 3909a8e commit 2df6c6f
Show file tree
Hide file tree
Showing 13 changed files with 111 additions and 111 deletions.
12 changes: 6 additions & 6 deletions spec/sandal/claims_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,38 @@
it 'calls #validate_aud when valid audiences are provided' do
claims = { 'aud' => 'example.org' }.extend(Sandal::Claims)
valid_aud = %w(example.org)
claims.should_receive(:validate_aud).with(valid_aud)
expect(claims).to receive(:validate_aud).with(valid_aud)
claims.validate_claims(valid_aud: valid_aud)
end

it 'calls #validate_exp by default' do
claims = {}.extend(Sandal::Claims)
claims.should_receive(:validate_exp)
expect(claims).to receive(:validate_exp)
claims.validate_claims
end

it 'does not call #validate_exp when the :ignore_exp option is set' do
claims = {}.extend(Sandal::Claims)
claims.should_not_receive(:validate_exp)
expect(claims).not_to receive(:validate_exp)
claims.validate_claims(ignore_exp: true)
end

it 'calls #validate_iss when valid issuers are provided' do
claims = { 'iss' => 'example.org' }.extend(Sandal::Claims)
valid_iss = %w(example.org)
claims.should_receive(:validate_iss).with(valid_iss)
expect(claims).to receive(:validate_iss).with(valid_iss)
claims.validate_claims(valid_iss: valid_iss)
end

it 'calls #validate_nbf by default' do
claims = {}.extend(Sandal::Claims)
claims.should_receive(:validate_nbf)
expect(claims).to receive(:validate_nbf)
claims.validate_claims
end

it 'does not call #validate_nbf when the :ignore_nbf option is set' do
claims = {}.extend(Sandal::Claims)
claims.should_not_receive(:validate_nbf)
expect(claims).not_to receive(:validate_nbf)
claims.validate_claims(ignore_nbf: true)
end

Expand Down
4 changes: 2 additions & 2 deletions spec/sandal/enc/a128cbc_hs256_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
context "#name" do
it "is 'A128CBC-HS256'" do
enc = Sandal::Enc::A128CBC_HS256.new(Sandal::Enc::Alg::Direct.new("a cmk"))
enc.name.should == "A128CBC-HS256"
expect(enc.name).to eq("A128CBC-HS256")
end
end

context "#decrypt" do
it "can decrypt the example token from JWE draft-11 appendix 2", :jruby_incompatible do
token="eyJhbGciOiJSU0ExXzUiLCJlbmMiOiJBMTI4Q0JDLUhTMjU2In0.UGhIOguC7IuEvf_NPVaXsGMoLOmwvc1GyqlIKOK1nN94nHPoltGRhWhw7Zx0-kFm1NJn8LE9XShH59_i8J0PH5ZZyNfGy2xGdULU7sHNF6Gp2vPLgNZ__deLKxGHZ7PcHALUzoOegEI-8E66jX2E4zyJKx-YxzZIItRzC5hlRirb6Y5Cl_p-ko3YvkkysZIFNPccxRU7qve1WYPxqbb2Yw8kZqa2rMWI5ng8OtvzlV7elprCbuPhcCdZ6XDP0_F8rkXds2vE4X-ncOIM8hAYHHi29NX0mcKiRaD0-D-ljQTP-cFPgwCp6X-nZZd9OHBv-B3oWh2TbqmScqXMR4gp_A.AxY8DCtDaGlsbGljb3RoZQ.KDlTtXchhZTGufMYmOYGS4HffxPSUrfmqCHXaI9wOGY.9hH0vgRfYgPnAHOd8stkvw"
enc = Sandal::Enc::A128CBC_HS256.new(Sandal::Enc::Alg::RSA1_5.new(SampleKeys.jwe_draft11_appendix2_rsa))
enc.decrypt(token).should == "Live long and prosper."
expect(enc.decrypt(token)).to eq("Live long and prosper.")
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/sandal/enc/a128gcm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
context "#name" do
it "is 'A128GCM'" do
enc = Sandal::Enc::A128GCM.new(Sandal::Enc::Alg::Direct.new("a cmk"))
enc.name.should == "A128GCM"
expect(enc.name).to eq("A128GCM")
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/sandal/enc/a256cbc_hs512_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
context "#name" do
it "is 'A256CBC-HS512'" do
enc = Sandal::Enc::A256CBC_HS512.new(Sandal::Enc::Alg::Direct.new("a cmk"))
enc.name.should == "A256CBC-HS512"
expect(enc.name).to eq("A256CBC-HS512")
end
end

Expand Down
4 changes: 2 additions & 2 deletions spec/sandal/enc/a256gcm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

it "is 'A256GCM'" do
enc = Sandal::Enc::A256GCM.new(Sandal::Enc::Alg::Direct.new("a cmk"))
enc.name.should == "A256GCM"
expect(enc.name).to eq("A256GCM")
end

end
Expand All @@ -21,7 +21,7 @@
it "can decrypt the example token from JWE draft-11 appendix 1", :jruby_incompatible do
token = "eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkEyNTZHQ00ifQ.OKOawDo13gRp2ojaHV7LFpZcgV7T6DVZKTyKOMTYUmKoTCVJRgckCL9kiMT03JGeipsEdY3mx_etLbbWSrFr05kLzcSr4qKAq7YN7e9jwQRb23nfa6c9d-StnImGyFDbSv04uVuxIp5Zms1gNxKKK2Da14B8S4rzVRltdYwam_lDp5XnZAYpQdb76FdIKLaVmqgfwX7XWRxv2322i-vDxRfqNzo_tETKzpVLzfiwQyeyPGLBIO56YJ7eObdv0je81860ppamavo35UgoRdbYaBcoh9QcfylQr66oc6vFWXRcZ_ZT2LawVCWTIy3brGPi6UklfCpIMfIjf7iGdXKHzg.48V1_ALb6US04U3b.5eym8TW_c8SuK0ltJ3rpYIzOeDQz7TALvtu6UG9oMo4vpzs9tX_EFShS8iB7j6jiSdiwkIr3ajwQzaBtQD_A.XFBoMYUZodetZdvTiFvSkQ"
enc = Sandal::Enc::A256GCM.new(Sandal::Enc::Alg::RSA_OAEP.new(SampleKeys.jwe_draft11_appendix1_rsa))
enc.decrypt(token).should == "The true sign of intelligence is not knowledge but imagination."
expect(enc.decrypt(token)).to eq("The true sign of intelligence is not knowledge but imagination.")
end
end

Expand Down
10 changes: 5 additions & 5 deletions spec/sandal/enc/alg/direct_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@
context "#name" do
it "is 'dir'" do
alg = Sandal::Enc::Alg::Direct.new("some key")
alg.name.should == "dir"
expect(alg.name).to eq("dir")
end
end

context "#preshared_key" do
it "returns the pre-shared key" do
key = "the pre-shared key"
alg = Sandal::Enc::Alg::Direct.new(key)
alg.preshared_key.should == key
expect(alg.preshared_key).to eq(key)
end
end

context "#encrypt_key" do
it "returns an empty string" do
alg = Sandal::Enc::Alg::Direct.new("the real key")
alg.encrypt_key("any value").should == ""
expect(alg.encrypt_key("any value")).to eq("")
end
end

Expand All @@ -30,13 +30,13 @@
it "returns the pre-shared content key when the value to decrypt is nil" do
key = "a pre-shared key"
alg = Sandal::Enc::Alg::Direct.new(key)
alg.decrypt_key(nil).should == key
expect(alg.decrypt_key(nil)).to eq(key)
end

it "returns the pre-shared content key when the value to decrypt is empty" do
key = "my pre-shared key"
alg = Sandal::Enc::Alg::Direct.new(key)
alg.decrypt_key("").should == key
expect(alg.decrypt_key("")).to eq(key)
end

it "raises an InvalidTokenError if the value to decrypt is not nil or empty" do
Expand Down
18 changes: 9 additions & 9 deletions spec/sandal/enc/alg/rsa_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@
encrypter = enc_class.new(key.public_key)
decrypter = enc_class.new(key)
key = "an encryption key"
decrypter.decrypt_key(encrypter.encrypt_key(key)).should == key
expect(decrypter.decrypt_key(encrypter.encrypt_key(key))).to eq(key)
end

it "can use DER-encoded keys to encrypt and decrypt a content master key" do
key = OpenSSL::PKey::RSA.new(2048)
encrypter = enc_class.new(key.public_key.to_der)
decrypter = enc_class.new(key.to_der)
key = "an encryption key"
decrypter.decrypt_key(encrypter.encrypt_key(key)).should == key
expect(decrypter.decrypt_key(encrypter.encrypt_key(key))).to eq(key)
end

it "can use PEM-encoded keys to encrypt and decrypt a content master key" do
key = OpenSSL::PKey::RSA.new(2048)
encrypter = enc_class.new(key.public_key.to_pem)
decrypter = enc_class.new(key.to_pem)
key = "an encryption key"
decrypter.decrypt_key(encrypter.encrypt_key(key)).should == key
expect(decrypter.decrypt_key(encrypter.encrypt_key(key))).to eq(key)
end

context "#decrypt_key" do
Expand Down Expand Up @@ -61,7 +61,7 @@
context "#name" do
it "is 'RSA1_5'" do
alg = Sandal::Enc::Alg::RSA1_5.new(OpenSSL::PKey::RSA.new(2048))
alg.name.should == "RSA1_5"
expect(alg.name).to eq("RSA1_5")
end
end

Expand All @@ -70,19 +70,19 @@
key = [4, 211, 31, 197, 84, 157, 252, 254, 11, 100, 157, 250, 63, 170, 106, 206, 107, 124, 212, 45, 111, 107, 9, 219, 200, 177, 0, 240, 143, 156, 44, 207].pack("C*")
encrypted_key = [80, 104, 72, 58, 11, 130, 236, 139, 132, 189, 255, 205, 61, 86, 151, 176, 99, 40, 44, 233, 176, 189, 205, 70, 202, 169, 72, 40, 226, 181, 156, 223, 120, 156, 115, 232, 150, 209, 145, 133, 104, 112, 237, 156, 116, 250, 65, 102, 212, 210, 103, 240, 177, 61, 93, 40, 71, 231, 223, 226, 240, 157, 15, 31, 150, 89, 200, 215, 198, 203, 108, 70, 117, 66, 212, 238, 193, 205, 23, 161, 169, 218, 243, 203, 128, 214, 127, 253, 215, 139, 43, 17, 135, 103, 179, 220, 28, 2, 212, 206, 131, 158, 128, 66, 62, 240, 78, 186, 141, 125, 132, 227, 60, 137, 43, 31, 152, 199, 54, 72, 34, 212, 115, 11, 152, 101, 70, 42, 219, 233, 142, 66, 151, 250, 126, 146, 141, 216, 190, 73, 50, 177, 146, 5, 52, 247, 28, 197, 21, 59, 170, 247, 181, 89, 131, 241, 169, 182, 246, 99, 15, 36, 102, 166, 182, 172, 197, 136, 230, 120, 60, 58, 219, 243, 149, 94, 222, 150, 154, 194, 110, 227, 225, 112, 39, 89, 233, 112, 207, 211, 241, 124, 174, 69, 221, 179, 107, 196, 225, 127, 167, 112, 226, 12, 242, 16, 24, 28, 120, 182, 244, 213, 244, 153, 194, 162, 69, 160, 244, 248, 63, 165, 141, 4, 207, 249, 193, 79, 131, 0, 169, 233, 127, 167, 101, 151, 125, 56, 112, 111, 248, 29, 232, 90, 29, 147, 110, 169, 146, 114, 165, 204, 71, 136, 41, 252].pack("C*")
alg = Sandal::Enc::Alg::RSA1_5.new(SampleKeys.jwe_draft11_appendix2_rsa)
alg.decrypt_key(encrypted_key).should == key
expect(alg.decrypt_key(encrypted_key)).to eq(key)
end
end

end

describe Sandal::Enc::Alg::RSA_OAEP do
include_examples "encryption and decryption", Sandal::Enc::Alg::RSA_OAEP
describe Sandal::Enc::Alg::RSA_OAEP do
include_examples "encryption and decryption", Sandal::Enc::Alg::RSA_OAEP

context "#name" do
it "is 'RSA-OAEP'" do
alg = Sandal::Enc::Alg::RSA_OAEP.new(OpenSSL::PKey::RSA.new(2048))
alg.name.should == "RSA-OAEP"
expect(alg.name).to eq("RSA-OAEP")
end
end

Expand All @@ -91,7 +91,7 @@
key = [177, 161, 244, 128, 84, 143, 225, 115, 63, 180, 3, 255, 107, 154, 212, 246, 138, 7, 110, 91, 112, 46, 34, 105, 47, 130, 203, 46, 122, 234, 64, 252].pack("C*")
encrypted_key = [56, 163, 154, 192, 58, 53, 222, 4, 105, 218, 136, 218, 29, 94, 203, 22, 150, 92, 129, 94, 211, 232, 53, 89, 41, 60, 138, 56, 196, 216, 82, 98, 168, 76, 37, 73, 70, 7, 36, 8, 191, 100, 136, 196, 244, 220, 145, 158, 138, 155, 4, 117, 141, 230, 199, 247, 173, 45, 182, 214, 74, 177, 107, 211, 153, 11, 205, 196, 171, 226, 162, 128, 171, 182, 13, 237, 239, 99, 193, 4, 91, 219, 121, 223, 107, 167, 61, 119, 228, 173, 156, 137, 134, 200, 80, 219, 74, 253, 56, 185, 91, 177, 34, 158, 89, 154, 205, 96, 55, 18, 138, 43, 96, 218, 215, 128, 124, 75, 138, 243, 85, 25, 109, 117, 140, 26, 155, 249, 67, 167, 149, 231, 100, 6, 41, 65, 214, 251, 232, 87, 72, 40, 182, 149, 154, 168, 31, 193, 126, 215, 89, 28, 111, 219, 125, 182, 139, 235, 195, 197, 23, 234, 55, 58, 63, 180, 68, 202, 206, 149, 75, 205, 248, 176, 67, 39, 178, 60, 98, 193, 32, 238, 122, 96, 158, 222, 57, 183, 111, 210, 55, 188, 215, 206, 180, 166, 150, 166, 106, 250, 55, 229, 72, 40, 69, 214, 216, 104, 23, 40, 135, 212, 28, 127, 41, 80, 175, 174, 168, 115, 171, 197, 89, 116, 92, 103, 246, 83, 216, 182, 176, 84, 37, 147, 35, 45, 219, 172, 99, 226, 233, 73, 37, 124, 42, 72, 49, 242, 35, 127, 184, 134, 117, 114, 135, 206].pack("C*")
alg = Sandal::Enc::Alg::RSA_OAEP.new(SampleKeys.jwe_draft11_appendix1_rsa)
alg.decrypt_key(encrypted_key).should == key
expect(alg.decrypt_key(encrypted_key)).to eq(key)
end
end

Expand Down
6 changes: 3 additions & 3 deletions spec/sandal/enc/shared_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
enc = enc_class.new(Sandal::Enc::Alg::Direct.new(content_encryption_key))
token = enc.encrypt("", payload)
output = enc.decrypt(token)
output.should == payload
expect(output).to eq(payload)
end

it "can encrypt and decrypt tokens with the RSA1_5 algorithm" do
Expand All @@ -19,7 +19,7 @@
token = encrypter.encrypt("", payload)
decrypter = enc_class.new(Sandal::Enc::Alg::RSA1_5.new(rsa))
output = decrypter.decrypt(token)
output.should == payload
expect(output).to eq(payload)
end

it "can encrypt and decrypt tokens with the RSA-OAEP algorithm" do
Expand All @@ -29,7 +29,7 @@
token = encrypter.encrypt("", payload)
decrypter = enc_class.new(Sandal::Enc::Alg::RSA_OAEP.new(rsa))
output = decrypter.decrypt(token)
output.should == payload
expect(output).to eq(payload)
end

end
Expand Down

0 comments on commit 2df6c6f

Please sign in to comment.