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 +4 -4
- data/.github/workflows/codecov.yml +1 -1
- data/.github/workflows/rake.yml +4 -4
- data/.github/workflows/xcop.yml +1 -1
- data/.rultor.yml +1 -1
- data/Gemfile +7 -7
- data/README.md +0 -1
- data/lib/glogin/auth.rb +1 -2
- data/lib/glogin/cookie.rb +9 -5
- data/lib/glogin/version.rb +1 -1
- data/test/glogin/test_cookie.rb +15 -15
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7e981c77fb4b32d821a8c6959a2772d37af2f4cf7133aa18374b662040bedcc
|
4
|
+
data.tar.gz: 4f87e9d5512dc2712ac91d770488a5fe799cdc069dfeeb2d6aecf32b0772af78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b59c8c6f1d5d763a8a9317aab9a27a73fe803406a6a3366efff7fefa9b6a298a079357f55854c08df6e05a2987a2415f2b23c1696a332c86d8f711512d50528e
|
7
|
+
data.tar.gz: 3a50c24837adee03fcc16ff3f42a216cd74bd16235c268b3b45194f7c2fc9c901c570c7a7323e966733895d908fac77b46f8b4583dc7b52b7f822d34b306eb7a
|
data/.github/workflows/rake.yml
CHANGED
@@ -8,15 +8,15 @@ on:
|
|
8
8
|
branches:
|
9
9
|
- master
|
10
10
|
jobs:
|
11
|
-
|
11
|
+
rake:
|
12
12
|
name: test
|
13
13
|
strategy:
|
14
14
|
matrix:
|
15
|
-
os: [ubuntu-
|
16
|
-
ruby: [2.7, 3.
|
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@
|
19
|
+
- uses: actions/checkout@v4
|
20
20
|
- uses: ruby/setup-ruby@v1
|
21
21
|
with:
|
22
22
|
ruby-version: ${{ matrix.ruby }}
|
data/.github/workflows/xcop.yml
CHANGED
data/.rultor.yml
CHANGED
data/Gemfile
CHANGED
@@ -24,11 +24,11 @@
|
|
24
24
|
source 'https://rubygems.org'
|
25
25
|
gemspec
|
26
26
|
|
27
|
-
gem 'minitest', '5.
|
28
|
-
gem 'rake', '13.1
|
29
|
-
gem 'rdoc', '6.
|
30
|
-
gem 'rspec-rails', '6.1.
|
31
|
-
gem 'rubocop', '1.
|
32
|
-
gem 'rubocop-rspec', '2.
|
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.
|
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
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`,
|
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,
|
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
|
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
|
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
|
)
|
data/lib/glogin/version.rb
CHANGED
data/test/glogin/test_cookie.rb
CHANGED
@@ -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\"
|
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[
|
42
|
-
assert_equal(user[
|
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":"#"
|
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[
|
58
|
-
assert_equal(user[
|
59
|
-
assert_equal(user[
|
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[
|
67
|
-
assert_equal(user[
|
68
|
-
assert_equal(user[
|
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[
|
76
|
-
assert_nil(user[
|
77
|
-
assert_nil(user[
|
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"
|
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":""
|
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.
|
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-
|
11
|
+
date: 2024-05-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: base58
|