glogin 0.14.1 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 43ce4ccebe57a06bb860c407b9e96dc939932f952aa2a6c4951a64f79a5f34c7
4
- data.tar.gz: 65854ae4920a4ff27bd67bcf7cf34d8222be36398639bd82b013fa73b94700a5
3
+ metadata.gz: a7e981c77fb4b32d821a8c6959a2772d37af2f4cf7133aa18374b662040bedcc
4
+ data.tar.gz: 4f87e9d5512dc2712ac91d770488a5fe799cdc069dfeeb2d6aecf32b0772af78
5
5
  SHA512:
6
- metadata.gz: c36870984ff3f36eb946b5bbb5273bc4f3633332651bd180196d1b172c7782248583285a0e3c9ae499205d45b6a45bb6e19910b7fb6ca8a455b0b2af8934c457
7
- data.tar.gz: 456ef6a6e5329d490d2195c58d3c8c007e23f6326f4535d362b04898451009926a5226baa384342b8dd889f6e00c17b8ef595d85e7a0e0fd5fa4a06c69324642
6
+ metadata.gz: b59c8c6f1d5d763a8a9317aab9a27a73fe803406a6a3366efff7fefa9b6a298a079357f55854c08df6e05a2987a2415f2b23c1696a332c86d8f711512d50528e
7
+ data.tar.gz: 3a50c24837adee03fcc16ff3f42a216cd74bd16235c268b3b45194f7c2fc9c901c570c7a7323e966733895d908fac77b46f8b4583dc7b52b7f822d34b306eb7a
@@ -8,7 +8,7 @@ jobs:
8
8
  codecov:
9
9
  runs-on: ubuntu-22.04
10
10
  steps:
11
- - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
11
+ - uses: actions/checkout@v4
12
12
  - uses: ruby/setup-ruby@v1
13
13
  with:
14
14
  ruby-version: 2.7
@@ -8,15 +8,15 @@ on:
8
8
  branches:
9
9
  - master
10
10
  jobs:
11
- test:
11
+ rake:
12
12
  name: test
13
13
  strategy:
14
14
  matrix:
15
- os: [ubuntu-20.04, macos-12]
16
- ruby: [2.7, 3.2]
15
+ os: [ubuntu-22.04, macos-12]
16
+ ruby: [2.7, 3.3]
17
17
  runs-on: ${{ matrix.os }}
18
18
  steps:
19
- - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
19
+ - uses: actions/checkout@v4
20
20
  - uses: ruby/setup-ruby@v1
21
21
  with:
22
22
  ruby-version: ${{ matrix.ruby }}
@@ -7,5 +7,5 @@ jobs:
7
7
  xcop:
8
8
  runs-on: ubuntu-22.04
9
9
  steps:
10
- - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
10
+ - uses: actions/checkout@v4
11
11
  - uses: g4s8/xcop-action@master
data/.rultor.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  docker:
2
- image: yegor256/rultor-image:1.22.0
2
+ image: yegor256/rultor-image:1.23.1
3
3
  assets:
4
4
  rubygems.yml: yegor256/home#assets/rubygems.yml
5
5
  install: |
data/Gemfile CHANGED
@@ -24,11 +24,11 @@
24
24
  source 'https://rubygems.org'
25
25
  gemspec
26
26
 
27
- gem 'minitest', '5.21.2', require: false
28
- gem 'rake', '13.1.0', require: false
29
- gem 'rdoc', '6.6.1', require: false
30
- gem 'rspec-rails', '6.1.0', require: false
31
- gem 'rubocop', '1.60.1', require: false
32
- gem 'rubocop-rspec', '2.26.1', require: false
27
+ gem 'minitest', '5.23.1', require: false
28
+ gem 'rake', '13.2.1', require: false
29
+ gem 'rdoc', '6.7.0', require: false
30
+ gem 'rspec-rails', '6.1.2', require: false
31
+ gem 'rubocop', '1.64.0', require: false
32
+ gem 'rubocop-rspec', '2.29.2', require: false
33
33
  gem 'simplecov', '0.22.0', require: false
34
- gem 'webmock', '3.19.1', require: false
34
+ gem 'webmock', '3.23.1', require: false
data/README.md CHANGED
@@ -9,7 +9,6 @@
9
9
  [![Maintainability](https://api.codeclimate.com/v1/badges/155f86b639d155259219/maintainability)](https://codeclimate.com/github/yegor256/glogin/maintainability)
10
10
  [![Test Coverage](https://img.shields.io/codecov/c/github/yegor256/glogin.svg)](https://codecov.io/github/yegor256/glogin?branch=master)
11
11
  [![Yard Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://rubydoc.info/github/yegor256/glogin/master/frames)
12
- ![Lines of code](https://img.shields.io/tokei/lines/github/yegor256/glogin)
13
12
  [![Hits-of-Code](https://hitsofcode.com/github/yegor256/glogin)](https://hitsofcode.com/view/github/yegor256/glogin)
14
13
  [![License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/yegor256/glogin/blob/master/LICENSE.txt)
15
14
 
data/lib/glogin/auth.rb CHANGED
@@ -57,8 +57,7 @@ module GLogin
57
57
  return {
58
58
  'id' => 526_301,
59
59
  'login' => 'yegor256',
60
- 'avatar_url' => 'https://github.com/yegor256.png',
61
- 'bearer' => ''
60
+ 'avatar_url' => 'https://github.com/yegor256.png'
62
61
  }
63
62
  end
64
63
  raise 'Code can\'t be nil' if code.nil?
data/lib/glogin/cookie.rb CHANGED
@@ -55,7 +55,7 @@ module GLogin
55
55
  @context = context.to_s
56
56
  end
57
57
 
58
- # Returns a hash with four elements: `id`, `login`, `avatar`, and `bearer`.
58
+ # Returns a hash with four elements: `id`, `login`, and `avatar_url`.
59
59
  #
60
60
  # If the `secret` is empty, the text will not be decrypted, but used
61
61
  # "as is". This may be helpful during testing.
@@ -65,23 +65,25 @@ module GLogin
65
65
  # to catch in your applicaiton and ignore the login attempt.
66
66
  def to_user
67
67
  plain = Codec.new(@secret).decrypt(@text)
68
- id, login, avatar, bearer, ctx = plain.split(GLogin::SPLIT, 5)
68
+ id, login, avatar_url, ctx = plain.split(GLogin::SPLIT, 5)
69
69
  if !@secret.empty? && ctx.to_s != @context
70
70
  raise(
71
71
  GLogin::Codec::DecodingError,
72
72
  "Context '#{@context}' expected, but '#{ctx}' found"
73
73
  )
74
74
  end
75
- { id: id, login: login, avatar: avatar, bearer: bearer }
75
+ { 'id' => id, 'login' => login, 'avatar_url' => avatar_url }
76
76
  end
77
77
  end
78
78
 
79
79
  # Open
80
80
  class Open
81
+ attr_reader :id, :login, :avatar_url
82
+
81
83
  # Here comes the JSON you receive from Auth.user().
82
84
  #
83
85
  # The JSON is a Hash where every key is a string. When the class is instantiated,
84
- # its methods +id+, +login+, and +avatar_url+ may be used to retrieve
86
+ # its methods `id`, `login`, and `avatar_url` may be used to retrieve
85
87
  # the data inside the JSON, but this is not what this class is mainly about.
86
88
  #
87
89
  # The method +to_s+ returns an encrypted cookie string, that may be
@@ -89,39 +91,28 @@ module GLogin
89
91
  def initialize(json, secret, context = '')
90
92
  raise 'JSON can\'t be nil' if json.nil?
91
93
  raise 'JSON must contain "id" key' if json['id'].nil?
92
- raise 'JSON must contain "login" key' if json['login'].nil?
93
- raise 'JSON must contain "avatar_url" key' if json['avatar_url'].nil?
94
- raise 'JSON must contain "bearer" key' if json['bearer'].nil?
95
- @json = json
94
+ json.each do |k, v|
95
+ raise "Key #{k} is not a string" unless k.is_a?(String)
96
+ raise "Key #{k} is not allowed" unless %w[id login avatar_url bearer].include?(k)
97
+ raise "Value #{v} is not a string" unless v.is_a?(String)
98
+ end
99
+ @id = json['id']
100
+ @login = json['login'] || ''
101
+ @avatar_url = json['avatar_url'] || ''
102
+ @bearer = json['bearer'] || ''
96
103
  raise 'Secret can\'t be nil' if secret.nil?
97
104
  @secret = secret
98
105
  raise 'Context can\'t be nil' if context.nil?
99
106
  @context = context.to_s
100
107
  end
101
108
 
102
- # GitHub id of the authenticated user
103
- def id
104
- @json['id']
105
- end
106
-
107
- # GitHub login name of the authenticated user
108
- def login
109
- @json['login']
110
- end
111
-
112
- # GitHub avatar URL of the authenticated user
113
- def avatar_url
114
- @json['avatar_url']
115
- end
116
-
117
109
  # Returns the text you should drop back to the user as a cookie.
118
110
  def to_s
119
111
  Codec.new(@secret).encrypt(
120
112
  [
121
- id,
122
- login,
123
- avatar_url,
124
- @json['bearer'],
113
+ @id,
114
+ @login,
115
+ @avatar_url,
125
116
  @context
126
117
  ].join(GLogin::SPLIT)
127
118
  )
@@ -26,5 +26,5 @@
26
26
  # Copyright:: Copyright (c) 2017-2024 Yegor Bugayenko
27
27
  # License:: MIT
28
28
  module GLogin
29
- VERSION = '0.14.1'
29
+ VERSION = '0.15.0'
30
30
  end
@@ -31,15 +31,15 @@ class TestCookie < Minitest::Test
31
31
  GLogin::Cookie::Open.new(
32
32
  JSON.parse(
33
33
  "{\"id\":\"123\",
34
- \"login\":\"yegor256\",\"bearer\":\"\",
34
+ \"login\":\"yegor256\",
35
35
  \"avatar_url\":\"https://avatars1.githubusercontent.com/u/526301\"}"
36
36
  ),
37
37
  secret
38
38
  ).to_s,
39
39
  secret
40
40
  ).to_user
41
- assert_equal(user[:login], 'yegor256')
42
- assert_equal(user[:avatar], 'https://avatars1.githubusercontent.com/u/526301')
41
+ assert_equal(user['login'], 'yegor256')
42
+ assert_equal(user['avatar_url'], 'https://avatars1.githubusercontent.com/u/526301')
43
43
  end
44
44
 
45
45
  def test_encrypts_and_decrypts_with_context
@@ -47,41 +47,41 @@ class TestCookie < Minitest::Test
47
47
  context = '127.0.0.1'
48
48
  user = GLogin::Cookie::Closed.new(
49
49
  GLogin::Cookie::Open.new(
50
- JSON.parse('{"id":"123","login":"jeffrey","avatar_url":"#","bearer":""}'),
50
+ JSON.parse('{"id":"123","login":"jeffrey","avatar_url":"#"}'),
51
51
  secret,
52
52
  context
53
53
  ).to_s,
54
54
  secret,
55
55
  context
56
56
  ).to_user
57
- assert_equal(user[:id], '123')
58
- assert_equal(user[:login], 'jeffrey')
59
- assert_equal(user[:avatar], '#')
57
+ assert_equal(user['id'], '123')
58
+ assert_equal(user['login'], 'jeffrey')
59
+ assert_equal(user['avatar_url'], '#')
60
60
  end
61
61
 
62
62
  def test_decrypts_in_test_mode
63
63
  user = GLogin::Cookie::Closed.new(
64
64
  '123|test|http://example.com', ''
65
65
  ).to_user
66
- assert_equal(user[:id], '123')
67
- assert_equal(user[:login], 'test')
68
- assert_equal(user[:avatar], 'http://example.com')
66
+ assert_equal(user['id'], '123')
67
+ assert_equal(user['login'], 'test')
68
+ assert_equal(user['avatar_url'], 'http://example.com')
69
69
  end
70
70
 
71
71
  def test_decrypts_in_test_mode_with_context
72
72
  user = GLogin::Cookie::Closed.new(
73
73
  '123', '', 'some context'
74
74
  ).to_user
75
- assert_equal('123', user[:id])
76
- assert_nil(user[:login])
77
- assert_nil(user[:avatar])
75
+ assert_equal('123', user['id'])
76
+ assert_nil(user['login'])
77
+ assert_nil(user['avatar_url'])
78
78
  end
79
79
 
80
80
  def test_fails_on_broken_text
81
81
  assert_raises GLogin::Codec::DecodingError do
82
82
  GLogin::Cookie::Closed.new(
83
83
  GLogin::Cookie::Open.new(
84
- JSON.parse('{"login":"x","avatar_url":"x","id":"1","bearer":""}'),
84
+ JSON.parse('{"login":"x","avatar_url":"x","id":"1"}'),
85
85
  'secret-1'
86
86
  ).to_s,
87
87
  'secret-2'
@@ -94,7 +94,7 @@ class TestCookie < Minitest::Test
94
94
  assert_raises GLogin::Codec::DecodingError do
95
95
  GLogin::Cookie::Closed.new(
96
96
  GLogin::Cookie::Open.new(
97
- JSON.parse('{"login":"x","avatar_url":"x","id":"999","bearer":""}'),
97
+ JSON.parse('{"login":"x","avatar_url":"x","id":""}'),
98
98
  secret,
99
99
  'context-1'
100
100
  ).to_s,
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glogin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.1
4
+ version: 0.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-22 00:00:00.000000000 Z
11
+ date: 2024-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: base58