-
Notifications
You must be signed in to change notification settings - Fork 981
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixup backward compatibility on top of cherry-pick commit
- Loading branch information
Showing
7 changed files
with
231 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'base64' | ||
|
||
module Faraday | ||
class Request | ||
# Authorization middleware for Basic Authentication. | ||
class BasicAuthentication < load_middleware(:authorization) | ||
# @param login [String] | ||
# @param pass [String] | ||
# | ||
# @return [String] a Basic Authentication header line | ||
def self.header(login, pass) | ||
value = Base64.encode64([login, pass].join(':')) | ||
value.delete!("\n") | ||
super(:Basic, value) | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
module Faraday | ||
class Request | ||
# TokenAuthentication is a middleware that adds a 'Token' header to a | ||
# Faraday request. | ||
class TokenAuthentication < load_middleware(:authorization) | ||
# Public | ||
def self.header(token, options = nil) | ||
options ||= {} | ||
options[:token] = token | ||
super(:Token, options) | ||
end | ||
|
||
def initialize(app, token, options = nil) | ||
super(app, token, options) | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -141,6 +141,28 @@ | |
end | ||
end | ||
|
||
describe 'basic_auth' do | ||
subject { conn } | ||
|
||
context 'calling the #basic_auth method' do | ||
before { subject.basic_auth 'Aladdin', 'open sesame' } | ||
|
||
it { expect(subject.headers['Authorization']).to eq('Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==') } | ||
end | ||
|
||
context 'adding basic auth info to url' do | ||
let(:url) { 'http://Aladdin:open%[email protected]/fish' } | ||
|
||
it { expect(subject.headers['Authorization']).to eq('Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==') } | ||
end | ||
end | ||
|
||
describe '#token_auth' do | ||
before { subject.token_auth('abcdef', nonce: 'abc') } | ||
|
||
it { expect(subject.headers['Authorization']).to eq('Token nonce="abc", token="abcdef"') } | ||
end | ||
|
||
describe '#build_exclusive_url' do | ||
context 'with relative path' do | ||
subject { conn.build_exclusive_url('sake.html') } | ||
|
@@ -583,6 +605,7 @@ | |
|
||
context 'after manual changes' do | ||
before do | ||
subject.basic_auth('', '') | ||
subject.headers['content-length'] = 12 | ||
subject.params['b'] = '2' | ||
subject.options[:open_timeout] = 10 | ||
|
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