glogin 0.14.2 → 0.15.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
  SHA256:
3
- metadata.gz: 56ba569dbb60a5e6e480c86cf2b5e103c6bd42d695e57d16bfc9b94a9b819526
4
- data.tar.gz: 4cd694c79226b6a7946caf4adac29ea10326f7944f89facb7b578c2ea1bc9034
3
+ metadata.gz: a7e981c77fb4b32d821a8c6959a2772d37af2f4cf7133aa18374b662040bedcc
4
+ data.tar.gz: 4f87e9d5512dc2712ac91d770488a5fe799cdc069dfeeb2d6aecf32b0772af78
5
5
  SHA512:
6
- metadata.gz: 37236f4de0ef6c6984c450cf03c0c6a79f51564911d3cf8a35408158d57153bfbda6c966cb0f5aa678e96c4482f89142d189f1d5054efd5b4c10227a01aa75d3
7
- data.tar.gz: 0f3a77248cd9c7ec6c925693ee125b8a34b86fd1def5d3f7e4bf45265d4a7ae46bf36b628444ce669e8da164116d57c88af6fb953e803520f6209bb3f066b954
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.2', 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,20 +65,20 @@ 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, :bearer
81
+ attr_reader :id, :login, :avatar_url
82
82
 
83
83
  # Here comes the JSON you receive from Auth.user().
84
84
  #
@@ -91,6 +91,11 @@ module GLogin
91
91
  def initialize(json, secret, context = '')
92
92
  raise 'JSON can\'t be nil' if json.nil?
93
93
  raise 'JSON must contain "id" key' if json['id'].nil?
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
94
99
  @id = json['id']
95
100
  @login = json['login'] || ''
96
101
  @avatar_url = json['avatar_url'] || ''
@@ -108,7 +113,6 @@ module GLogin
108
113
  @id,
109
114
  @login,
110
115
  @avatar_url,
111
- @bearer,
112
116
  @context
113
117
  ].join(GLogin::SPLIT)
114
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.2'
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":"","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.2
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-24 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