|
23 | 23 | github.client.token_url.should == 'https://github.com/login/oauth/access_token' |
24 | 24 | end |
25 | 25 |
|
| 26 | + context '.client' do |
| 27 | + it { github.should respond_to :client } |
| 28 | + |
| 29 | + it "should return OAuth2::Client instance" do |
| 30 | + github.client.should be_a OAuth2::Client |
| 31 | + end |
| 32 | + end |
| 33 | + |
| 34 | + context '.auth_code' do |
| 35 | + let(:oauth) { OAuth2::Client.new(client_id, client_secret) } |
| 36 | + |
| 37 | + before do |
| 38 | + github = Github.new :client_id => client_id, :client_secret => client_secret |
| 39 | + end |
| 40 | + |
| 41 | + after do |
| 42 | + github.client_id, github.client_secret = nil, nil |
| 43 | + end |
| 44 | + |
| 45 | + it "should throw an error if no client_id" do |
| 46 | + github.client_id = nil |
| 47 | + expect { github.auth_code }.should raise_error(ArgumentError) |
| 48 | + end |
| 49 | + |
| 50 | + it "should throw an error if no client_secret" do |
| 51 | + github.client_secret = nil |
| 52 | + expect { github.auth_code }.should raise_error(ArgumentError) |
| 53 | + end |
| 54 | + |
| 55 | + it "should return authentication token code" do |
| 56 | + github.client_id = client_id |
| 57 | + github.client_secret = client_secret |
| 58 | + github.client.stub(:auth_code).and_return code |
| 59 | + github.auth_code.should == code |
| 60 | + end |
| 61 | + end |
| 62 | + |
26 | 63 | context "authorize_url" do |
27 | 64 | before do |
28 | 65 | github = Github.new :client_id => client_id, :client_secret => client_secret |
|
68 | 105 | end |
69 | 106 | end |
70 | 107 |
|
| 108 | + context ".authenticated?" do |
| 109 | + it { github.should respond_to :authenticated? } |
| 110 | + |
| 111 | + it "should return false if falied on basic authentication" do |
| 112 | + github.stub(:basic_authed?).and_return false |
| 113 | + github.authenticated?.should be_false |
| 114 | + end |
| 115 | + |
| 116 | + it "should return true if basic authentication performed" do |
| 117 | + github.stub(:basic_authed?).and_return true |
| 118 | + github.authenticated?.should be_true |
| 119 | + end |
| 120 | + |
| 121 | + it "should return true if basic authentication performed" do |
| 122 | + github.stub(:oauth_token?).and_return true |
| 123 | + github.authenticated?.should be_true |
| 124 | + end |
| 125 | + end |
| 126 | + |
| 127 | + context ".basic_authed?" do |
| 128 | + it { github.should respond_to :basic_authed? } |
| 129 | + |
| 130 | + it "should return false if login is missing" do |
| 131 | + github.stub(:login?).and_return false |
| 132 | + github.basic_authed?.should be_false |
| 133 | + end |
| 134 | + |
| 135 | + it "should return true if login && password provided" do |
| 136 | + github.stub(:login?).and_return true |
| 137 | + github.stub(:password?).and_return true |
| 138 | + github.basic_authed?.should be_true |
| 139 | + end |
| 140 | + end |
| 141 | + |
71 | 142 | context "authentication" do |
72 | 143 | it "should respond to 'authentication'" do |
73 | 144 | github.should respond_to :authentication |
74 | 145 | end |
75 | 146 |
|
| 147 | + it "should return empty hash if no basic authentication params available" do |
| 148 | + github.stub(:login?).and_return false |
| 149 | + github.stub(:basic_auth?).and_return false |
| 150 | + github.authentication.should be_empty |
| 151 | + end |
| 152 | + |
76 | 153 | context 'basic_auth' do |
77 | 154 | before do |
78 | 155 | github = Github.new :basic_auth => 'github:pass' |
|
0 commit comments