spec/lib/oauth/client/credentials_spec.rb in doorkeeper-sequel-1.2.1 vs spec/lib/oauth/client/credentials_spec.rb in doorkeeper-sequel-1.2.2
- old
+ new
@@ -2,10 +2,13 @@
require 'active_support/core_ext/string'
require 'doorkeeper/oauth/client'
class Doorkeeper::OAuth::Client
describe Credentials do
+ let(:client_id) { 'some-uid' }
+ let(:client_secret) { 'some-secret' }
+
it 'is blank when any of the credentials is blank' do
expect(Credentials.new(nil, 'something')).to be_blank
expect(Credentials.new('something', nil)).to be_blank
end
@@ -39,9 +42,47 @@
it 'returns uid and secret from extractor method' do
credentials = Credentials.from_request request, method
expect(credentials.uid).to eq('uid')
expect(credentials.secret).to eq('secret')
+ end
+ end
+
+ describe :from_params do
+ it 'returns credentials from parameters when Authorization header is not available' do
+ request = double parameters: { client_id: client_id, client_secret: client_secret }
+ uid, secret = Credentials.from_params(request)
+
+ expect(uid).to eq('some-uid')
+ expect(secret).to eq('some-secret')
+ end
+
+ it 'is blank when there are no credentials' do
+ request = double parameters: {}
+ uid, secret = Credentials.from_params(request)
+
+ expect(uid).to be_blank
+ expect(secret).to be_blank
+ end
+ end
+
+ describe :from_basic do
+ let(:credentials) { Base64.encode64("#{client_id}:#{client_secret}") }
+
+ it 'decodes the credentials' do
+ request = double authorization: "Basic #{credentials}"
+ uid, secret = Credentials.from_basic(request)
+
+ expect(uid).to eq('some-uid')
+ expect(secret).to eq('some-secret')
+ end
+
+ it 'is blank if Authorization is not Basic' do
+ request = double authorization: "#{credentials}"
+ uid, secret = Credentials.from_basic(request)
+
+ expect(uid).to be_blank
+ expect(secret).to be_blank
end
end
end
end