Skip to content

Commit

Permalink
Make the RbNaCl dependent tests optional
Browse files Browse the repository at this point in the history
  • Loading branch information
anakinj committed Oct 23, 2020
1 parent 72b003a commit 2a5fbbc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -10,6 +10,7 @@ rvm:
gemfile:
- gemfiles/standalone.gemfile
- gemfiles/openssl_2.1.gemfile
- gemfiles/rbnacl.gemfile
script:
- bundle exec rspec
- bundle exec codeclimate-test-reporter
Expand Down
5 changes: 5 additions & 0 deletions gemfiles/rbnacl.gemfile
@@ -0,0 +1,5 @@
source "https://rubygems.org"

gem "rbnacl"

gemspec path: "../"
16 changes: 11 additions & 5 deletions spec/jwt_spec.rb
Expand Up @@ -7,7 +7,7 @@
let(:payload) { { 'user_id' => 'some@user.tld' } }

let :data do
{
data = {
:secret => 'My$ecretK3y',
:rsa_private => OpenSSL::PKey.read(File.read(File.join(CERT_PATH, 'rsa-2048-private.pem'))),
:rsa_public => OpenSSL::PKey.read(File.read(File.join(CERT_PATH, 'rsa-2048-public.pem'))),
Expand All @@ -19,8 +19,6 @@
'ES384_public' => OpenSSL::PKey.read(File.read(File.join(CERT_PATH, 'ec384-public.pem'))),
'ES512_private' => OpenSSL::PKey.read(File.read(File.join(CERT_PATH, 'ec512-private.pem'))),
'ES512_public' => OpenSSL::PKey.read(File.read(File.join(CERT_PATH, 'ec512-public.pem'))),
'ED25519_private' => RbNaCl::Signatures::Ed25519::SigningKey.new('abcdefghijklmnopqrstuvwxyzABCDEF'),
'ED25519_public' => RbNaCl::Signatures::Ed25519::SigningKey.new('abcdefghijklmnopqrstuvwxyzABCDEF').verify_key,
'NONE' => 'eyJhbGciOiJub25lIn0.eyJ1c2VyX2lkIjoic29tZUB1c2VyLnRsZCJ9.',
'HS256' => 'eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoic29tZUB1c2VyLnRsZCJ9.kWOVtIOpWcG7JnyJG0qOkTDbOy636XrrQhMm_8JrRQ8',
'HS512256' => 'eyJhbGciOiJIUzUxMjI1NiJ9.eyJ1c2VyX2lkIjoic29tZUB1c2VyLnRsZCJ9.Ds_4ibvf7z4QOBoKntEjDfthy3WJ-3rKMspTEcHE2bA',
Expand All @@ -36,6 +34,14 @@
'PS384' => '',
'PS512' => ''
}

if defined?(RbNaCl)
data.merge!(
'ED25519_private' => RbNaCl::Signatures::Ed25519::SigningKey.new('abcdefghijklmnopqrstuvwxyzABCDEF'),
'ED25519_public' => RbNaCl::Signatures::Ed25519::SigningKey.new('abcdefghijklmnopqrstuvwxyzABCDEF').verify_key,
)
end
data
end

after(:each) do
Expand Down Expand Up @@ -110,7 +116,7 @@
JWT.encode payload, "secret", JWT::Algos::Hmac::SUPPORTED.sample
end
end

if defined?(RbNaCl)
%w[HS256 HS512256 HS384 HS512].each do |alg|
context "alg: #{alg}" do
it 'should generate a valid token' do
Expand Down Expand Up @@ -300,7 +306,7 @@
end
end
end

end
context 'Invalid' do
it 'algorithm should raise NotImplementedError' do
expect do
Expand Down

0 comments on commit 2a5fbbc

Please sign in to comment.