-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprivate_key_helper_spec.rb
37 lines (30 loc) · 1.24 KB
/
private_key_helper_spec.rb
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
# frozen_string_literal: true
require 'spec_helper'
require 'mauth/client'
describe MAuth::PrivateKeyHelper do
let(:private_key) { OpenSSL::PKey::RSA.generate(2048).to_s }
let(:private_key_newlines_replaced_with_spaces) { private_key.tr("\n", ' ') }
let(:private_key_no_newlines) { private_key.delete("\n") }
let(:private_key_invalid) { 'abc' }
describe 'generate' do
it 'returns a RSA object' do
expect(described_class.generate).to be_a_kind_of(OpenSSL::PKey::RSA)
end
end
describe 'load' do
it 'loads a private key string and returns a RSA object' do
expect(described_class.load(private_key).to_s).to eq(private_key)
end
it 'loads a private key string (newlines are replaced with spaces) and returns a RSA object' do
expect(described_class.load(private_key_newlines_replaced_with_spaces).to_s).to eq(private_key)
end
it 'loads a private key string (newlines are removed) and returns a RSA object' do
expect(described_class.load(private_key_no_newlines).to_s).to eq(private_key)
end
it 'raises an error if the private key string is invalid' do
expect do
described_class.load(private_key_invalid)
end.to raise_error('The private key provided is invalid')
end
end
end