-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
11 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
let(:tempfile) { Tempfile.new } | ||
let(:key) { OpenSSL::PKey::RSA.new(2048) } | ||
|
||
before :each do | ||
before do | ||
LetsEncrypt.class_eval do | ||
@private_key = nil | ||
@endpoint = nil | ||
|
@@ -16,38 +16,37 @@ | |
end | ||
|
||
describe '#generate_private_key' do | ||
it 'create a new private key' do | ||
key = LetsEncrypt.generate_private_key | ||
expect(LetsEncrypt.private_key.to_s).to eq(key.to_s) | ||
end | ||
let!(:key) { LetsEncrypt.generate_private_key } | ||
|
||
it { expect(LetsEncrypt.private_key.to_s).to eq(key.to_s) } | ||
end | ||
|
||
describe '#register' do | ||
let(:acme_client) { double(Acme::Client) } | ||
let(:acme_account) { double } | ||
|
||
it 'register new account to Let\'s Encrypt' do | ||
before do | ||
tempfile.write(key.to_s) | ||
tempfile.rewind | ||
|
||
allow(LetsEncrypt).to receive(:client).and_return(acme_client) | ||
allow(acme_client).to receive(:new_account).and_return(acme_account) | ||
allow(acme_account).to receive(:kid).and_return('') | ||
|
||
LetsEncrypt.register('[email protected]') | ||
end | ||
|
||
it { expect(LetsEncrypt.register('[email protected]')).to be_truthy } | ||
end | ||
|
||
describe 'certificate_model' do | ||
before do | ||
stub_const('OtherModel', Class.new(LetsEncrypt::Certificate)) | ||
|
||
LetsEncrypt.config.certificate_model = 'OtherModel' | ||
|
||
allow(LetsEncrypt).to receive(:certificate_model) { LetsEncrypt.config.certificate_model.constantize } | ||
end | ||
|
||
after { LetsEncrypt.config.certificate_model = 'LetsEncrypt::Certificate' } | ||
it 'set the certificate_model to customize model' do | ||
expect(LetsEncrypt.certificate_model).to eq('OtherModel'.constantize) | ||
end | ||
|
||
it { expect(LetsEncrypt).to have_attributes(certificate_model: OtherModel) } | ||
end | ||
end |