octoauth 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3918e6a2c1d30b4f4fa12d2f4fb6a7a64f7ab608
4
- data.tar.gz: 246fbe321144407f610f712e9fdfacd824ef0b3c
3
+ metadata.gz: b80d12c3505ddbe37c6237f2df7d01b56bdb75e7
4
+ data.tar.gz: 82234ad8872138f5630f5c7b52ea273d16f6c685
5
5
  SHA512:
6
- metadata.gz: 77aa2d21dd8b6c079888704e5102faecc3a2d3de4c757908b07f73045f96d54f8c5a98b28ea9b42d3fc72809b21172735353344c3ba2f0302d88eea7a8109888
7
- data.tar.gz: d2070fe16197bea8bcd5bba83cae237e49e02baed5a504735d1679807fa72f4f9056a5e9dac66d996ded32b0aef88c3488499c3c6941d98524b4fb4bebbb8c0c
6
+ metadata.gz: 77de129784d3b6656dc153bec66542c246d96314d8ea9f5028d7fdaf610a9969b83330a2b063bec1ec7887257dc7de79c558f1cda7d73e9a979a5bb39ceab202
7
+ data.tar.gz: bfc7c32f131c8049614783f9b73c4e1b1d5c0d9b86e4e65f5347bda3c38a1ec81768d219905d2578c69625482237fb4443b8240a9504f4fcd4167c2166782ef2
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 1.3.0 / 2015-08-22
2
+
3
+ * [ENHANCEMENT] Updated octokit to ~> 4.1.0
4
+
1
5
  # 1.2.0 / 2015-06-27
2
6
 
3
7
  * [ENHANCEMENT] Update octokit to ~> 4.0.0
data/lib/octoauth/auth.rb CHANGED
@@ -61,10 +61,21 @@ module Octoauth
61
61
  "#{@options[:note]}--#{@options[:api_endpoint]}"
62
62
  end
63
63
 
64
+ def fingerprint
65
+ @fingerprint ||= "#{config_note}/#{hostname}"
66
+ end
67
+
68
+ def hostname
69
+ return @hostname if @hostname
70
+ res = `hostname`.split.first
71
+ @hostname = $?.exitstatus == 0 ? res : 'NULL'
72
+ end
73
+
64
74
  def prompt!(needs2fa = false)
65
75
  @options[:login] ||= PROMPTS[:login].ask
66
76
  @options[:password] ||= PROMPTS[:password].ask
67
77
  @options[:scopes] ||= DEFAULT_SCOPES
78
+ @options[:fingerprint] = fingerprint
68
79
  return unless needs2fa
69
80
  @options[:twofactor] ||= PROMPTS[:twofactor].ask
70
81
  @options[:headers] = { 'X-GitHub-OTP' => @options[:twofactor] }
@@ -81,7 +92,7 @@ module Octoauth
81
92
  @options.subset(:login, :password, :api_endpoint)
82
93
  )
83
94
  client.create_authorization(
84
- @options.subset(:note, :scopes, :headers)
95
+ @options.subset(:note, :scopes, :headers, :fingerprint)
85
96
  ).token
86
97
  rescue Octokit::OneTimePasswordRequired
87
98
  load_token(true)
data/octoauth.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'octoauth'
3
- s.version = '1.2.0'
3
+ s.version = '1.3.0'
4
4
  s.date = Time.now.strftime("%Y-%m-%d")
5
5
 
6
6
  s.summary = 'Auth token helper for GitHub API'
@@ -13,13 +13,14 @@ Gem::Specification.new do |s|
13
13
  s.files = `git ls-files`.split
14
14
  s.test_files = `git ls-files spec/*`.split
15
15
 
16
- s.add_dependency 'octokit', '~> 4.0.0'
16
+ s.add_dependency 'octokit', '~> 4.1.0'
17
17
  s.add_dependency 'userinput', '~> 1.0.0'
18
18
 
19
- s.add_development_dependency 'rubocop', '~> 0.32.0'
19
+ s.add_development_dependency 'rubocop', '~> 0.33.0'
20
20
  s.add_development_dependency 'rake', '~> 10.4.0'
21
21
  s.add_development_dependency 'coveralls', '~> 0.8.0'
22
22
  s.add_development_dependency 'rspec', '~> 3.3.0'
23
23
  s.add_development_dependency 'fuubar', '~> 2.0.0'
24
24
  s.add_development_dependency 'webmock', '~> 1.21.0'
25
+ s.add_development_dependency 'vcr', '~> 2.9.2'
25
26
  end
@@ -0,0 +1,63 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://user:pw@api.github.com/authorizations
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"note":"foo","scopes":[],"fingerprint":"foo/bean"}'
9
+ headers:
10
+ Accept:
11
+ - application/vnd.github.v3+json
12
+ User-Agent:
13
+ - Octokit Ruby Gem 4.0.1
14
+ Content-Type:
15
+ - application/json
16
+ Accept-Encoding:
17
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
18
+ response:
19
+ status:
20
+ code: 401
21
+ message: Unauthorized
22
+ headers:
23
+ Server:
24
+ - GitHub.com
25
+ Date:
26
+ - Sat, 25 Jul 2015 01:56:58 GMT
27
+ Content-Type:
28
+ - application/json; charset=utf-8
29
+ Content-Length:
30
+ - '83'
31
+ Status:
32
+ - 401 Unauthorized
33
+ X-Github-Media-Type:
34
+ - github.v3; format=json
35
+ X-Ratelimit-Limit:
36
+ - '60'
37
+ X-Ratelimit-Remaining:
38
+ - '54'
39
+ X-Ratelimit-Reset:
40
+ - '1437793018'
41
+ X-Xss-Protection:
42
+ - 1; mode=block
43
+ X-Frame-Options:
44
+ - deny
45
+ Content-Security-Policy:
46
+ - default-src 'none'
47
+ Access-Control-Allow-Credentials:
48
+ - 'true'
49
+ Access-Control-Expose-Headers:
50
+ - ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset,
51
+ X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval
52
+ Access-Control-Allow-Origin:
53
+ - "*"
54
+ Strict-Transport-Security:
55
+ - max-age=31536000; includeSubdomains; preload
56
+ X-Content-Type-Options:
57
+ - nosniff
58
+ body:
59
+ encoding: UTF-8
60
+ string: '{"message":"Bad credentials","documentation_url":"https://developer.github.com/v3"}'
61
+ http_version:
62
+ recorded_at: Sat, 25 Jul 2015 01:56:58 GMT
63
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,63 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://user:pw@api.github.com/authorizations
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"note":"autosave_test","scopes":[],"fingerprint":"autosave_test/bean"}'
9
+ headers:
10
+ Accept:
11
+ - application/vnd.github.v3+json
12
+ User-Agent:
13
+ - Octokit Ruby Gem 4.0.1
14
+ Content-Type:
15
+ - application/json
16
+ Accept-Encoding:
17
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
18
+ response:
19
+ status:
20
+ code: 401
21
+ message: Unauthorized
22
+ headers:
23
+ Server:
24
+ - GitHub.com
25
+ Date:
26
+ - Sat, 25 Jul 2015 01:56:58 GMT
27
+ Content-Type:
28
+ - application/json; charset=utf-8
29
+ Content-Length:
30
+ - '83'
31
+ Status:
32
+ - 401 Unauthorized
33
+ X-Github-Media-Type:
34
+ - github.v3; format=json
35
+ X-Ratelimit-Limit:
36
+ - '60'
37
+ X-Ratelimit-Remaining:
38
+ - '58'
39
+ X-Ratelimit-Reset:
40
+ - '1437793018'
41
+ X-Xss-Protection:
42
+ - 1; mode=block
43
+ X-Frame-Options:
44
+ - deny
45
+ Content-Security-Policy:
46
+ - default-src 'none'
47
+ Access-Control-Allow-Credentials:
48
+ - 'true'
49
+ Access-Control-Expose-Headers:
50
+ - ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset,
51
+ X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval
52
+ Access-Control-Allow-Origin:
53
+ - "*"
54
+ Strict-Transport-Security:
55
+ - max-age=31536000; includeSubdomains; preload
56
+ X-Content-Type-Options:
57
+ - nosniff
58
+ body:
59
+ encoding: UTF-8
60
+ string: '{"message":"Bad credentials","documentation_url":"https://developer.github.com/v3"}'
61
+ http_version:
62
+ recorded_at: Sat, 25 Jul 2015 01:56:58 GMT
63
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,63 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://user:pw@api.github.com/authorizations
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"note":"existing","scopes":[],"fingerprint":"existing/bean"}'
9
+ headers:
10
+ Accept:
11
+ - application/vnd.github.v3+json
12
+ User-Agent:
13
+ - Octokit Ruby Gem 4.0.1
14
+ Content-Type:
15
+ - application/json
16
+ Accept-Encoding:
17
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
18
+ response:
19
+ status:
20
+ code: 401
21
+ message: Unauthorized
22
+ headers:
23
+ Server:
24
+ - GitHub.com
25
+ Date:
26
+ - Sat, 25 Jul 2015 01:56:58 GMT
27
+ Content-Type:
28
+ - application/json; charset=utf-8
29
+ Content-Length:
30
+ - '83'
31
+ Status:
32
+ - 401 Unauthorized
33
+ X-Github-Media-Type:
34
+ - github.v3; format=json
35
+ X-Ratelimit-Limit:
36
+ - '60'
37
+ X-Ratelimit-Remaining:
38
+ - '57'
39
+ X-Ratelimit-Reset:
40
+ - '1437793018'
41
+ X-Xss-Protection:
42
+ - 1; mode=block
43
+ X-Frame-Options:
44
+ - deny
45
+ Content-Security-Policy:
46
+ - default-src 'none'
47
+ Access-Control-Allow-Credentials:
48
+ - 'true'
49
+ Access-Control-Expose-Headers:
50
+ - ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset,
51
+ X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval
52
+ Access-Control-Allow-Origin:
53
+ - "*"
54
+ Strict-Transport-Security:
55
+ - max-age=31536000; includeSubdomains; preload
56
+ X-Content-Type-Options:
57
+ - nosniff
58
+ body:
59
+ encoding: UTF-8
60
+ string: '{"message":"Bad credentials","documentation_url":"https://developer.github.com/v3"}'
61
+ http_version:
62
+ recorded_at: Sat, 25 Jul 2015 01:56:58 GMT
63
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,63 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://user:pw@api.github.com/authorizations
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"note":"foo","scopes":[],"fingerprint":"foo/bean"}'
9
+ headers:
10
+ Accept:
11
+ - application/vnd.github.v3+json
12
+ User-Agent:
13
+ - Octokit Ruby Gem 4.0.1
14
+ Content-Type:
15
+ - application/json
16
+ Accept-Encoding:
17
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
18
+ response:
19
+ status:
20
+ code: 401
21
+ message: Unauthorized
22
+ headers:
23
+ Server:
24
+ - GitHub.com
25
+ Date:
26
+ - Sat, 25 Jul 2015 01:56:58 GMT
27
+ Content-Type:
28
+ - application/json; charset=utf-8
29
+ Content-Length:
30
+ - '83'
31
+ Status:
32
+ - 401 Unauthorized
33
+ X-Github-Media-Type:
34
+ - github.v3; format=json
35
+ X-Ratelimit-Limit:
36
+ - '60'
37
+ X-Ratelimit-Remaining:
38
+ - '55'
39
+ X-Ratelimit-Reset:
40
+ - '1437793018'
41
+ X-Xss-Protection:
42
+ - 1; mode=block
43
+ X-Frame-Options:
44
+ - deny
45
+ Content-Security-Policy:
46
+ - default-src 'none'
47
+ Access-Control-Allow-Credentials:
48
+ - 'true'
49
+ Access-Control-Expose-Headers:
50
+ - ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset,
51
+ X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval
52
+ Access-Control-Allow-Origin:
53
+ - "*"
54
+ Strict-Transport-Security:
55
+ - max-age=31536000; includeSubdomains; preload
56
+ X-Content-Type-Options:
57
+ - nosniff
58
+ body:
59
+ encoding: UTF-8
60
+ string: '{"message":"Bad credentials","documentation_url":"https://developer.github.com/v3"}'
61
+ http_version:
62
+ recorded_at: Sat, 25 Jul 2015 01:56:58 GMT
63
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,63 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://user:pw@api.github.com/authorizations
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"note":"foo","scopes":[],"fingerprint":"foo/bean"}'
9
+ headers:
10
+ Accept:
11
+ - application/vnd.github.v3+json
12
+ User-Agent:
13
+ - Octokit Ruby Gem 4.0.1
14
+ Content-Type:
15
+ - application/json
16
+ Accept-Encoding:
17
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
18
+ response:
19
+ status:
20
+ code: 401
21
+ message: Unauthorized
22
+ headers:
23
+ Server:
24
+ - GitHub.com
25
+ Date:
26
+ - Sat, 25 Jul 2015 01:56:58 GMT
27
+ Content-Type:
28
+ - application/json; charset=utf-8
29
+ Content-Length:
30
+ - '83'
31
+ Status:
32
+ - 401 Unauthorized
33
+ X-Github-Media-Type:
34
+ - github.v3; format=json
35
+ X-Ratelimit-Limit:
36
+ - '60'
37
+ X-Ratelimit-Remaining:
38
+ - '56'
39
+ X-Ratelimit-Reset:
40
+ - '1437793018'
41
+ X-Xss-Protection:
42
+ - 1; mode=block
43
+ X-Frame-Options:
44
+ - deny
45
+ Content-Security-Policy:
46
+ - default-src 'none'
47
+ Access-Control-Allow-Credentials:
48
+ - 'true'
49
+ Access-Control-Expose-Headers:
50
+ - ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset,
51
+ X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval
52
+ Access-Control-Allow-Origin:
53
+ - "*"
54
+ Strict-Transport-Security:
55
+ - max-age=31536000; includeSubdomains; preload
56
+ X-Content-Type-Options:
57
+ - nosniff
58
+ body:
59
+ encoding: UTF-8
60
+ string: '{"message":"Bad credentials","documentation_url":"https://developer.github.com/v3"}'
61
+ http_version:
62
+ recorded_at: Sat, 25 Jul 2015 01:56:58 GMT
63
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,63 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://user:pw@api.github.com/authorizations
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"note":"foo","scopes":["gist","delete_repo"],"fingerprint":"foo/bean"}'
9
+ headers:
10
+ Accept:
11
+ - application/vnd.github.v3+json
12
+ User-Agent:
13
+ - Octokit Ruby Gem 4.0.1
14
+ Content-Type:
15
+ - application/json
16
+ Accept-Encoding:
17
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
18
+ response:
19
+ status:
20
+ code: 401
21
+ message: Unauthorized
22
+ headers:
23
+ Server:
24
+ - GitHub.com
25
+ Date:
26
+ - Sat, 25 Jul 2015 01:56:58 GMT
27
+ Content-Type:
28
+ - application/json; charset=utf-8
29
+ Content-Length:
30
+ - '83'
31
+ Status:
32
+ - 401 Unauthorized
33
+ X-Github-Media-Type:
34
+ - github.v3; format=json
35
+ X-Ratelimit-Limit:
36
+ - '60'
37
+ X-Ratelimit-Remaining:
38
+ - '59'
39
+ X-Ratelimit-Reset:
40
+ - '1437793018'
41
+ X-Xss-Protection:
42
+ - 1; mode=block
43
+ X-Frame-Options:
44
+ - deny
45
+ Content-Security-Policy:
46
+ - default-src 'none'
47
+ Access-Control-Allow-Credentials:
48
+ - 'true'
49
+ Access-Control-Expose-Headers:
50
+ - ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset,
51
+ X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval
52
+ Access-Control-Allow-Origin:
53
+ - "*"
54
+ Strict-Transport-Security:
55
+ - max-age=31536000; includeSubdomains; preload
56
+ X-Content-Type-Options:
57
+ - nosniff
58
+ body:
59
+ encoding: UTF-8
60
+ string: '{"message":"Bad credentials","documentation_url":"https://developer.github.com/v3"}'
61
+ http_version:
62
+ recorded_at: Sat, 25 Jul 2015 01:56:58 GMT
63
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,63 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://user:pw@api.github.com/authorizations
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"note":"write_test","scopes":[],"fingerprint":"write_test/bean"}'
9
+ headers:
10
+ Accept:
11
+ - application/vnd.github.v3+json
12
+ User-Agent:
13
+ - Octokit Ruby Gem 4.0.1
14
+ Content-Type:
15
+ - application/json
16
+ Accept-Encoding:
17
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
18
+ response:
19
+ status:
20
+ code: 401
21
+ message: Unauthorized
22
+ headers:
23
+ Server:
24
+ - GitHub.com
25
+ Date:
26
+ - Sat, 25 Jul 2015 01:56:59 GMT
27
+ Content-Type:
28
+ - application/json; charset=utf-8
29
+ Content-Length:
30
+ - '83'
31
+ Status:
32
+ - 401 Unauthorized
33
+ X-Github-Media-Type:
34
+ - github.v3; format=json
35
+ X-Ratelimit-Limit:
36
+ - '60'
37
+ X-Ratelimit-Remaining:
38
+ - '53'
39
+ X-Ratelimit-Reset:
40
+ - '1437793018'
41
+ X-Xss-Protection:
42
+ - 1; mode=block
43
+ X-Frame-Options:
44
+ - deny
45
+ Content-Security-Policy:
46
+ - default-src 'none'
47
+ Access-Control-Allow-Credentials:
48
+ - 'true'
49
+ Access-Control-Expose-Headers:
50
+ - ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset,
51
+ X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval
52
+ Access-Control-Allow-Origin:
53
+ - "*"
54
+ Strict-Transport-Security:
55
+ - max-age=31536000; includeSubdomains; preload
56
+ X-Content-Type-Options:
57
+ - nosniff
58
+ body:
59
+ encoding: UTF-8
60
+ string: '{"message":"Bad credentials","documentation_url":"https://developer.github.com/v3"}'
61
+ http_version:
62
+ recorded_at: Sat, 25 Jul 2015 01:56:59 GMT
63
+ recorded_with: VCR 2.9.3
@@ -22,121 +22,85 @@ describe Octoauth do
22
22
  describe '#initialize' do
23
23
  context 'if the file and note already exist' do
24
24
  it 'loads the existing token' do
25
- auth = Octoauth::Auth.new(
26
- note: 'foo',
27
- file: 'spec/examples/conf_a.yml'
28
- )
29
- expect(auth.token).to eql 'bcdebcdebcdebcdebcdebcdebcde'
25
+ VCR.use_cassette('load_existing_token') do
26
+ auth = Octoauth::Auth.new(
27
+ note: 'foo',
28
+ file: 'spec/examples/conf_a.yml'
29
+ )
30
+ expect(auth.token).to eql 'bcdebcdebcdebcdebcdebcdebcde'
31
+ end
30
32
  end
31
33
  end
32
34
  context 'if there is a note conflict' do
33
- it 'returns the existing token' do
34
- stub_request(:post, 'https://user:pw@api.github.com/authorizations')
35
- .with(body: "{\"note\":\"existing\",\"scopes\":[]}")
36
- .to_return(status: 422)
37
- stub_request(:get, 'https://user:pw@api.github.com/authorizations')
38
- .to_return(
39
- status: 200,
40
- body: [
41
- AuthShim.new('not_match', 'bad'),
42
- AuthShim.new('existing', 'existing_token')
43
- ]
35
+ it 'creates_a_new_token' do
36
+ VCR.use_cassette('creates_new_token') do
37
+ auth = Octoauth::Auth.new(
38
+ note: 'existing',
39
+ login: 'user',
40
+ password: 'pw'
44
41
  )
45
- auth = Octoauth::Auth.new(
46
- note: 'existing',
47
- login: 'user',
48
- password: 'pw'
49
- )
50
- expect(auth.token).to eql 'existing_token'
42
+ expect(auth.token).to eql 'existing_token'
43
+ end
51
44
  end
52
45
  end
53
46
  context 'if the file does not exist' do
54
47
  it 'requests user input to create token' do
55
- stub_request(:post, 'https://user:pw@api.github.com/authorizations')
56
- .with(body: "{\"note\":\"foo\",\"scopes\":[]}")
57
- .to_return(
58
- status: 200,
59
- body: AuthShim.new('foo', 'qwertyqwertyqwertyqwerty')
48
+ VCR.use_cassette('request_user_input') do
49
+ auth = Octoauth::Auth.new(
50
+ note: 'foo',
51
+ login: 'user',
52
+ password: 'pw'
60
53
  )
61
- auth = Octoauth::Auth.new(
62
- note: 'foo',
63
- login: 'user',
64
- password: 'pw'
65
- )
66
- expect(auth.token).to eql 'qwertyqwertyqwertyqwerty'
54
+ expect(auth.token).to eql 'qwertyqwertyqwertyqwerty'
55
+ end
67
56
  end
68
57
  it 'handles users with 2 factor auth enabled' do
69
- stub_request(:post, 'https://user:pw@api.github.com/authorizations')
70
- .with(body: "{\"note\":\"foo\",\"scopes\":[]}")
71
- .to_return(
72
- status: 401,
73
- headers: { 'X-GitHub-OTP' => 'required; app' }
74
- )
75
- stub_request(:post, 'https://user:pw@api.github.com/authorizations')
76
- .with(
77
- body: "{\"note\":\"foo\",\"scopes\":[]}",
78
- headers: { 'X-GitHub-OTP' => '1234' }
79
- )
80
- .to_return(
81
- status: 200,
82
- body: AuthShim.new('foo', 'qwertyqwertyqwertyqwerty')
83
- )
84
- allow(STDIN).to receive(:gets).and_return("user\n", "pw\n", "1234\n")
85
- auth = Octoauth::Auth.new(note: 'foo')
86
- expect(auth.token).to eql 'qwertyqwertyqwertyqwerty'
58
+ VCR.use_cassette('handle_two_factor') do
59
+ allow(STDIN).to receive(:gets).and_return("user\n", "pw\n", "1234\n")
60
+ auth = Octoauth::Auth.new(note: 'foo')
61
+ expect(auth.token).to eql 'qwertyqwertyqwertyqwerty'
62
+ end
87
63
  end
88
64
  end
89
65
  it 'supports alternate endpoints' do
90
- stub_request(:post, 'https://user:pw@sekrit.com/api/v3/authorizations')
91
- .with(body: "{\"note\":\"foo\",\"scopes\":[]}")
92
- .to_return(
93
- status: 200,
94
- body: AuthShim.new('foo', 'qwertyqwertyqwertyqwerty')
66
+ VCR.use_cassette('alternate_endpoints') do
67
+ auth = Octoauth::Auth.new(
68
+ note: 'foo',
69
+ login: 'user',
70
+ password: 'pw',
71
+ api_endpoint: 'https://sekrit.com/api/v3/'
95
72
  )
96
- auth = Octoauth::Auth.new(
97
- note: 'foo',
98
- login: 'user',
99
- password: 'pw',
100
- api_endpoint: 'https://sekrit.com/api/v3/'
101
- )
102
- expect(auth.token).to eql 'qwertyqwertyqwertyqwerty'
73
+ expect(auth.token).to eql 'qwertyqwertyqwertyqwerty'
74
+ end
103
75
  end
104
76
  it 'supports requesting scopes' do
105
- stub_request(:post, 'https://user:pw@api.github.com/authorizations')
106
- .with(body: '{"note":"foo","scopes":["gist","delete_repo"]}')
107
- .to_return(
108
- status: 200,
109
- body: AuthShim.new('foo', 'qwertyqwertyqwertyqwerty')
77
+ VCR.use_cassette('requesting_scopes') do
78
+ auth = Octoauth::Auth.new(
79
+ note: 'foo',
80
+ login: 'user',
81
+ password: 'pw',
82
+ scopes: %w(gist delete_repo)
110
83
  )
111
- auth = Octoauth::Auth.new(
112
- note: 'foo',
113
- login: 'user',
114
- password: 'pw',
115
- scopes: %w(gist delete_repo)
116
- )
117
- expect(auth.token).to eql 'qwertyqwertyqwertyqwerty'
84
+ expect(auth.token).to eql 'qwertyqwertyqwertyqwerty'
85
+ end
118
86
  end
119
87
  it 'supports autosaving the config file' do
120
- random = rand(36**30).to_s(30)
121
- stub_request(:post, 'https://user:pw@api.github.com/authorizations')
122
- .with(body: "{\"note\":\"autosave_test\",\"scopes\":[]}")
123
- .to_return(
124
- status: 200,
125
- body: AuthShim.new('foo', random)
88
+ VCR.use_cassette('autosaving_config_file') do
89
+ random = rand(36**30).to_s(30)
90
+ FileUtils.rm_f 'spec/examples/autosave.yml'
91
+ Octoauth::Auth.new(
92
+ note: 'autosave_test',
93
+ file: 'spec/examples/autosave.yml',
94
+ login: 'user',
95
+ password: 'pw',
96
+ autosave: true
97
+ )
98
+ new_auth = Octoauth::Auth.new(
99
+ note: 'autosave_test',
100
+ file: 'spec/examples/autosave.yml'
126
101
  )
127
- FileUtils.rm_f 'spec/examples/autosave.yml'
128
- Octoauth::Auth.new(
129
- note: 'autosave_test',
130
- file: 'spec/examples/autosave.yml',
131
- login: 'user',
132
- password: 'pw',
133
- autosave: true
134
- )
135
- new_auth = Octoauth::Auth.new(
136
- note: 'autosave_test',
137
- file: 'spec/examples/autosave.yml'
138
- )
139
- expect(new_auth.token).to eql random
102
+ expect(new_auth.token).to eql random
103
+ end
140
104
  end
141
105
  end
142
106
  context 'when given multiple file paths' do
@@ -170,26 +134,22 @@ describe Octoauth do
170
134
  expect(auth.send(:config).token).to be_nil
171
135
  end
172
136
  it 'writes to the first file' do
173
- random = rand(36**30).to_s(30)
174
- stub_request(:post, 'https://user:pw@api.github.com/authorizations')
175
- .with(body: "{\"note\":\"foo\",\"scopes\":[]}")
176
- .to_return(
177
- status: 200,
178
- body: AuthShim.new('foo', random)
137
+ VCR.use_cassette('Write_to_first_file') do
138
+ random = rand(36**30).to_s(30)
139
+ FileUtils.rm_f ['spec/examples/nil.yml', 'spec/examples/nil2.yml']
140
+ auth = Octoauth::Auth.new(
141
+ note: 'foo',
142
+ files: ['spec/examples/nil.yml', 'spec/examples/nil2.yml'],
143
+ login: 'user',
144
+ password: 'pw'
179
145
  )
180
- FileUtils.rm_f ['spec/examples/nil.yml', 'spec/examples/nil2.yml']
181
- auth = Octoauth::Auth.new(
182
- note: 'foo',
183
- files: ['spec/examples/nil.yml', 'spec/examples/nil2.yml'],
184
- login: 'user',
185
- password: 'pw'
186
- )
187
- auth.save
188
- new_auth = Octoauth::Auth.new(
189
- note: 'foo',
190
- file: 'spec/examples/nil.yml'
191
- )
192
- expect(new_auth.token).to eql random
146
+ auth.save
147
+ new_auth = Octoauth::Auth.new(
148
+ note: 'foo',
149
+ file: 'spec/examples/nil.yml'
150
+ )
151
+ expect(new_auth.token).to eql random
152
+ end
193
153
  end
194
154
  end
195
155
  end
@@ -197,26 +157,22 @@ describe Octoauth do
197
157
 
198
158
  describe '#save' do
199
159
  it 'saves the config to disk' do
200
- random = rand(36**30).to_s(30)
201
- FileUtils.rm_f 'spec/examples/tmp.yml'
202
- stub_request(:post, 'https://user:pw@api.github.com/authorizations')
203
- .with(body: "{\"note\":\"write_test\",\"scopes\":[]}")
204
- .to_return(
205
- status: 200,
206
- body: AuthShim.new('foo', random)
160
+ VCR.use_cassette('save_to_disk') do
161
+ random = rand(36**30).to_s(30)
162
+ FileUtils.rm_f 'spec/examples/tmp.yml'
163
+ auth = Octoauth::Auth.new(
164
+ note: 'write_test',
165
+ file: 'spec/examples/tmp.yml',
166
+ login: 'user',
167
+ password: 'pw'
168
+ )
169
+ auth.save
170
+ new_auth = Octoauth::Auth.new(
171
+ note: 'write_test',
172
+ file: 'spec/examples/tmp.yml'
207
173
  )
208
- auth = Octoauth::Auth.new(
209
- note: 'write_test',
210
- file: 'spec/examples/tmp.yml',
211
- login: 'user',
212
- password: 'pw'
213
- )
214
- auth.save
215
- new_auth = Octoauth::Auth.new(
216
- note: 'write_test',
217
- file: 'spec/examples/tmp.yml'
218
- )
219
- expect(new_auth.token).to eql random
174
+ expect(new_auth.token).to eql random
175
+ end
220
176
  end
221
177
  end
222
178
  end
@@ -3,13 +3,10 @@ require 'spec_helper'
3
3
  describe Octoauth do
4
4
  describe '#new' do
5
5
  it 'creates auth objects' do
6
- stub_request(:post, 'https://good:sekrit@api.github.com/authorizations')
7
- .to_return(
8
- status: 200,
9
- body: Struct.new(:token).new('abcdabcdabcdabcdabcdabcdabcdabcdabcd')
10
- )
11
- auth = Octoauth.new note: 'testing', login: 'good', password: 'sekrit'
12
- expect(auth).to be_an_instance_of Octoauth::Auth
6
+ VCR.use_cassette('creates_auth_objects') do
7
+ auth = Octoauth.new note: 'testing', login: 'good', password: 'sekrit'
8
+ expect(auth).to be_an_instance_of Octoauth::Auth
9
+ end
13
10
  end
14
11
  end
15
12
  end
data/spec/spec_helper.rb CHANGED
@@ -9,15 +9,15 @@ end
9
9
  require 'rspec'
10
10
  require 'octoauth'
11
11
 
12
- require 'webmock/rspec'
13
- WebMock.disable_net_connect!(allow_localhost: true)
14
-
15
- module WebMock
16
- ##
17
- # Patch WebMock to allow Structs as response bodies
18
- class Response
19
- def assert_valid_body!
20
- true
12
+ require 'vcr'
13
+ VCR.configure do |c|
14
+ c.cassette_library_dir = 'spec/fixtures/cassettes'
15
+ c.hook_into :webmock
16
+ c.before_record do |i|
17
+ i.request.headers.delete 'Authorization'
18
+ %w(Etag X-Github-Request-Id X-Served-By).each do |header|
19
+ i.response.headers.delete header
21
20
  end
22
21
  end
23
22
  end
23
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: octoauth
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Les Aker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-27 00:00:00.000000000 Z
11
+ date: 2015-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: octokit
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 4.0.0
19
+ version: 4.1.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 4.0.0
26
+ version: 4.1.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: userinput
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.32.0
47
+ version: 0.33.0
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 0.32.0
54
+ version: 0.33.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -122,6 +122,20 @@ dependencies:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
124
  version: 1.21.0
125
+ - !ruby/object:Gem::Dependency
126
+ name: vcr
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 2.9.2
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 2.9.2
125
139
  description: Lightweight wrapper to sanely handle OAuth tokens with Octokit
126
140
  email: me@lesaker.org
127
141
  executables: []
@@ -142,6 +156,13 @@ files:
142
156
  - lib/octoauth/configfile.rb
143
157
  - octoauth.gemspec
144
158
  - spec/examples/conf_a.yml
159
+ - spec/fixtures/cassettes/Write_to_first_file.yml
160
+ - spec/fixtures/cassettes/autosaving_config_file.yml
161
+ - spec/fixtures/cassettes/creates_new_token.yml
162
+ - spec/fixtures/cassettes/handle_two_factor.yml
163
+ - spec/fixtures/cassettes/request_user_input.yml
164
+ - spec/fixtures/cassettes/requesting_scopes.yml
165
+ - spec/fixtures/cassettes/save_to_disk.yml
145
166
  - spec/octoauth/auth_spec.rb
146
167
  - spec/octoauth/configfile_spec.rb
147
168
  - spec/octoauth_spec.rb
@@ -172,6 +193,13 @@ specification_version: 4
172
193
  summary: Auth token helper for GitHub API
173
194
  test_files:
174
195
  - spec/examples/conf_a.yml
196
+ - spec/fixtures/cassettes/Write_to_first_file.yml
197
+ - spec/fixtures/cassettes/autosaving_config_file.yml
198
+ - spec/fixtures/cassettes/creates_new_token.yml
199
+ - spec/fixtures/cassettes/handle_two_factor.yml
200
+ - spec/fixtures/cassettes/request_user_input.yml
201
+ - spec/fixtures/cassettes/requesting_scopes.yml
202
+ - spec/fixtures/cassettes/save_to_disk.yml
175
203
  - spec/octoauth/auth_spec.rb
176
204
  - spec/octoauth/configfile_spec.rb
177
205
  - spec/octoauth_spec.rb