Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some default options, and move config.
- Loading branch information
Erich Menge
committed
Apr 17, 2013
1 parent
8004292
commit 2a044f6
Showing
11 changed files
with
140 additions
and
85 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
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
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
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
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
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
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
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 |
---|---|---|
@@ -1,34 +1,24 @@ | ||
require 'spec_helper' | ||
|
||
describe SignedForm::HMAC do | ||
describe 'create_hmac' do | ||
it 'should raise if no key is given' do | ||
expect { SignedForm::HMAC.create_hmac "foo" }.to raise_error(SignedForm::Errors::NoSecretKey) | ||
end | ||
it 'should raise if no key is given' do | ||
expect { SignedForm::HMAC.new }.to raise_error(SignedForm::Errors::NoSecretKey) | ||
end | ||
|
||
context 'when a key is present' do | ||
before { SignedForm::HMAC.secret_key = "superdupersecret" } | ||
after { SignedForm::HMAC.secret_key = nil } | ||
describe 'create' do | ||
let(:hmac) { SignedForm::HMAC.new(secret_key: "superdupersecret") } | ||
|
||
it 'should create a hex signature' do | ||
SignedForm::HMAC.create_hmac("my signed message").length.should == 40 | ||
end | ||
it 'should create a hex signature' do | ||
hmac.create("my signed message").length.should == 40 | ||
hmac.create("my signed message").should == "93c1ecd4c10122cbf873ca6cf9eff08888565054" | ||
end | ||
end | ||
|
||
describe 'verify_hmac' do | ||
it 'should raise if no key is given' do | ||
expect { SignedForm::HMAC.verify_hmac 'foo', 'bar' }.to raise_error(SignedForm::Errors::NoSecretKey) | ||
end | ||
|
||
context 'when a key is present' do | ||
before { SignedForm::HMAC.secret_key = "superdupersecret" } | ||
after { SignedForm::HMAC.secret_key = nil } | ||
|
||
let(:signature) { SignedForm::HMAC.create_hmac "My super secret" } | ||
describe 'verify' do | ||
let(:hmac) { SignedForm::HMAC.new(secret_key: "superdupersecret") } | ||
let(:signature) { hmac.create "My super secret" } | ||
|
||
specify { SignedForm::HMAC.verify_hmac(signature, "My super secret").should be_true } | ||
specify { SignedForm::HMAC.verify_hmac(signature, "My bad secret").should_not be_true } | ||
end | ||
specify { hmac.verify(signature, "My super secret").should be_true } | ||
specify { hmac.verify(signature, "My bad secret").should_not be_true } | ||
end | ||
end |
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
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
require 'spec_helper' | ||
|
||
describe SignedForm do | ||
it "should reset the hmac object secret key if the secret key changes" do | ||
SignedForm.secret_key = "foo" | ||
|
||
SignedForm.hmac.secret_key.should == "foo" | ||
SignedForm.secret_key = "bar" | ||
SignedForm.hmac.secret_key.should == "bar" | ||
end | ||
end |
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