forked from piotrmurach/github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoauth2_spec.rb
More file actions
70 lines (55 loc) · 1.86 KB
/
oauth2_spec.rb
File metadata and controls
70 lines (55 loc) · 1.86 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
require 'spec_helper'
describe Github::Request::OAuth2 do
include Github::Utils::Url
def auth_header(env)
env[:request_headers]['Authorization']
end
def middleware
described_class.new(lambda { |env| env }, options)
end
def process(params={}, headers={})
env = {
:url => URI('http://example.com/?' + build_query(params)),
:request_headers => headers
}
middleware.call(env)
end
context 'no token configured' do
let(:options) { nil }
it "doesn't add params" do
result = process(:q => 'query')
result[:url].query.should eql 'q=query'
end
it "doesn't add headers" do
auth_header(process).should be_nil
end
it "allows for ad hoc access token" do
result = process(:q => 'query', :access_token => 'abc123')
result[:url].query.should eql 'access_token=abc123&q=query'
end
it "creates header for ad hoc access token" do
result = process(:q => 'query', :access_token => 'abc123')
auth_header(result).should eql 'Token token="abc123"'
end
end
context 'default token configured' do
let(:options) { 'ABC' }
it "adds access token to params" do
result = process(:q => 'query')
result[:url].query.should eql 'access_token=ABC&q=query'
end
it "creates header for access token" do
auth_header(process).should eql 'Token token="ABC"'
end
it "overrides default with explicit token" do
result = process(:q => 'query', :access_token => 'abc123')
result[:url].query.should eql 'access_token=abc123&q=query'
auth_header(result).should eql 'Token token="abc123"'
end
it "clears default token with explicit one" do
result = process(:q => 'query', :access_token => nil)
result[:url].query.should eql 'q=query&access_token'
auth_header(result).should be_nil
end
end
end # Github::Request::OAuth2