glogin 0.16.4 → 0.17.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.
data/lib/glogin/cookie.rb CHANGED
@@ -1,51 +1,74 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- #
4
- # Copyright (c) 2017-2024 Yegor Bugayenko
5
- #
6
- # Permission is hereby granted, free of charge, to any person obtaining a copy
7
- # of this software and associated documentation files (the 'Software'), to deal
8
- # in the Software without restriction, including without limitation the rights
9
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- # copies of the Software, and to permit persons to whom the Software is
11
- # furnished to do so, subject to the following conditions:
12
- #
13
- # The above copyright notice and this permission notice shall be included in all
14
- # copies or substantial portions of the Software.
15
- #
16
- # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
19
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- # SOFTWARE.
3
+ # SPDX-FileCopyrightText: Copyright (c) 2017-2025 Yegor Bugayenko
4
+ # SPDX-License-Identifier: MIT
23
5
 
24
- require 'openssl'
25
- require 'digest/sha1'
26
6
  require 'base64'
7
+ require 'digest/sha1'
8
+ require 'openssl'
27
9
  require_relative 'codec'
28
10
 
29
11
  # GLogin main module.
30
12
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
31
- # Copyright:: Copyright (c) 2017-2024 Yegor Bugayenko
13
+ # Copyright:: Copyright (c) 2017-2025 Yegor Bugayenko
32
14
  # License:: MIT
33
15
  module GLogin
34
16
  # Split symbol inside the cookie text
35
17
  SPLIT = '|'
36
18
 
19
+ # Secure cookie management for user sessions.
20
+ #
21
+ # This class provides two nested classes for handling cookies:
22
+ # - Cookie::Open: Creates encrypted cookies from user data
23
+ # - Cookie::Closed: Decrypts and validates existing cookies
37
24
  #
38
- # Secure cookie
25
+ # The cookie format stores user ID, login, avatar URL, and an optional
26
+ # context string for additional security validation.
39
27
  #
28
+ # @example Creating and reading a cookie
29
+ # # After successful authentication
30
+ # user_data = auth.user(code)
31
+ # cookie = GLogin::Cookie::Open.new(user_data, 'secret-key')
32
+ # response.set_cookie('glogin', cookie.to_s)
33
+ #
34
+ # # When reading the cookie
35
+ # cookie_text = request.cookies['glogin']
36
+ # closed = GLogin::Cookie::Closed.new(cookie_text, 'secret-key')
37
+ # user = closed.to_user
38
+ # # => {"id"=>"123", "login"=>"username", "avatar_url"=>"https://..."}
40
39
  class Cookie
41
- # Closed cookie.
40
+ # Closed cookie for reading existing cookies.
42
41
  #
43
42
  # An instance of this class is created when a cookie arrives
44
- # to the application. The cookie text is provided to the class
45
- # as the first parameter. Then, when an instance of the class
46
- # is created, the value encypted inside the cookie text may
47
- # be retrieved through the +to_user+ method.
43
+ # from the client. The encrypted cookie text is decrypted to
44
+ # retrieve the original user information.
45
+ #
46
+ # @example Read a cookie from HTTP request
47
+ # cookie_text = request.cookies['glogin']
48
+ # closed = GLogin::Cookie::Closed.new(cookie_text, ENV['SECRET'])
49
+ #
50
+ # begin
51
+ # user = closed.to_user
52
+ # session[:user_id] = user['id']
53
+ # rescue GLogin::Codec::DecodingError
54
+ # # Invalid cookie - redirect to login
55
+ # redirect '/login'
56
+ # end
57
+ #
58
+ # @example Using context for additional security
59
+ # closed = GLogin::Cookie::Closed.new(
60
+ # cookie_text,
61
+ # ENV['SECRET'],
62
+ # request.ip # Validate against IP address
63
+ # )
64
+ # user = closed.to_user
48
65
  class Closed
66
+ # Creates a new closed cookie instance.
67
+ #
68
+ # @param text [String] The encrypted cookie text to decrypt
69
+ # @param secret [String] The secret key used for decryption
70
+ # @param context [String] Optional context string for validation
71
+ # @raise [RuntimeError] if any parameter is nil
49
72
  def initialize(text, secret, context = '')
50
73
  raise 'Text can\'t be nil' if text.nil?
51
74
  @text = text
@@ -55,14 +78,27 @@ module GLogin
55
78
  @context = context.to_s
56
79
  end
57
80
 
58
- # Returns a hash with four elements: `id`, `login`, and `avatar_url`.
81
+ # Decrypts and returns the user information from the cookie.
59
82
  #
60
- # If the `secret` is empty, the text will not be decrypted, but used
61
- # "as is". This may be helpful during testing.
83
+ # @return [Hash] User information with keys 'id', 'login', and 'avatar_url'
84
+ # @raise [GLogin::Codec::DecodingError] if:
85
+ # - The cookie is corrupted or tampered with
86
+ # - The wrong secret key is used
87
+ # - The context doesn't match (if provided)
88
+ # @example Basic usage
89
+ # user = closed.to_user
90
+ # # => {"id"=>"123", "login"=>"octocat", "avatar_url"=>"https://..."}
62
91
  #
63
- # If the data is not valid, an exception
64
- # `GLogin::Codec::DecodingError` will be raised, which you have
65
- # to catch in your applicaiton and ignore the login attempt.
92
+ # @example Error handling
93
+ # begin
94
+ # user = closed.to_user
95
+ # puts "Welcome, #{user['login']}!"
96
+ # rescue GLogin::Codec::DecodingError => e
97
+ # puts "Invalid session: #{e.message}"
98
+ # redirect_to_login
99
+ # end
100
+ #
101
+ # @note If the secret is empty (test mode), the text is used as-is without decryption
66
102
  def to_user
67
103
  plain = Codec.new(@secret).decrypt(@text)
68
104
  id, login, avatar_url, ctx = plain.split(GLogin::SPLIT, 5)
@@ -76,18 +112,50 @@ module GLogin
76
112
  end
77
113
  end
78
114
 
79
- # Open
115
+ # Open cookie for creating new cookies.
116
+ #
117
+ # This class takes user information from GitHub authentication
118
+ # and creates an encrypted cookie that can be sent to the client.
119
+ #
120
+ # @example Create a cookie after successful authentication
121
+ # user_data = auth.user(code)
122
+ # open = GLogin::Cookie::Open.new(user_data, ENV['SECRET'])
123
+ #
124
+ # # Set cookie with options
125
+ # response.set_cookie('glogin', {
126
+ # value: open.to_s,
127
+ # expires: 1.week.from_now,
128
+ # httponly: true,
129
+ # secure: true
130
+ # })
131
+ #
132
+ # @example Using context for IP-based validation
133
+ # open = GLogin::Cookie::Open.new(
134
+ # user_data,
135
+ # ENV['SECRET'],
136
+ # request.ip # Bind cookie to IP address
137
+ # )
138
+ # response.set_cookie('glogin', open.to_s)
80
139
  class Open
81
140
  attr_reader :id, :login, :avatar_url
82
141
 
83
- # Here comes the JSON you receive from Auth.user().
142
+ # Creates a new open cookie from user data.
84
143
  #
85
- # The JSON is a Hash where every key is a string. When the class is instantiated,
86
- # its methods `id`, `login`, and `avatar_url` may be used to retrieve
87
- # the data inside the JSON, but this is not what this class is mainly about.
88
- #
89
- # The method +to_s+ returns an encrypted cookie string, that may be
90
- # sent to the user as a +Set-Cookie+ HTTP header.
144
+ # @param json [Hash] User data from Auth#user, must contain 'id' key
145
+ # @param secret [String] Secret key for encryption
146
+ # @param context [String] Optional context for additional validation
147
+ # @raise [RuntimeError] if json is nil or missing 'id' key
148
+ # @raise [RuntimeError] if secret or context is nil
149
+ # @example
150
+ # user_data = {
151
+ # 'id' => '123456',
152
+ # 'login' => 'octocat',
153
+ # 'avatar_url' => 'https://github.com/octocat.png'
154
+ # }
155
+ # open = GLogin::Cookie::Open.new(user_data, 'secret-key')
156
+ # puts open.id # => "123456"
157
+ # puts open.login # => "octocat"
158
+ # puts open.avatar_url # => "https://github.com/octocat.png"
91
159
  def initialize(json, secret, context = '')
92
160
  raise 'JSON can\'t be nil' if json.nil?
93
161
  raise 'JSON must contain "id" key' if json['id'].nil?
@@ -101,7 +169,27 @@ module GLogin
101
169
  @context = context.to_s
102
170
  end
103
171
 
104
- # Returns the text you should drop back to the user as a cookie.
172
+ # Generates the encrypted cookie string.
173
+ #
174
+ # This method encrypts the user information (id, login, avatar_url, and context)
175
+ # into a string that can be sent as an HTTP cookie. The encryption ensures
176
+ # the cookie cannot be tampered with.
177
+ #
178
+ # @return [String] The encrypted cookie value
179
+ # @example Generate cookie for HTTP response
180
+ # open = GLogin::Cookie::Open.new(user_data, secret)
181
+ # cookie_value = open.to_s
182
+ # # => "3Hs9k2LgU..." (encrypted string)
183
+ #
184
+ # # Use with Sinatra
185
+ # response.set_cookie('glogin', cookie_value)
186
+ #
187
+ # # Use with Rails
188
+ # cookies[:glogin] = {
189
+ # value: cookie_value,
190
+ # expires: 1.week.from_now,
191
+ # httponly: true
192
+ # }
105
193
  def to_s
106
194
  Codec.new(@secret).encrypt(
107
195
  [
@@ -1,30 +1,22 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- #
4
- # Copyright (c) 2017-2024 Yegor Bugayenko
5
- #
6
- # Permission is hereby granted, free of charge, to any person obtaining a copy
7
- # of this software and associated documentation files (the 'Software'), to deal
8
- # in the Software without restriction, including without limitation the rights
9
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- # copies of the Software, and to permit persons to whom the Software is
11
- # furnished to do so, subject to the following conditions:
12
- #
13
- # The above copyright notice and this permission notice shall be included in all
14
- # copies or substantial portions of the Software.
15
- #
16
- # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
19
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- # SOFTWARE.
3
+ # SPDX-FileCopyrightText: Copyright (c) 2017-2025 Yegor Bugayenko
4
+ # SPDX-License-Identifier: MIT
23
5
 
24
6
  # GLogin main module.
25
7
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
26
- # Copyright:: Copyright (c) 2017-2024 Yegor Bugayenko
8
+ # Copyright:: Copyright (c) 2017-2025 Yegor Bugayenko
27
9
  # License:: MIT
28
10
  module GLogin
29
- VERSION = '0.16.4'
11
+ # Current version of the GLogin gem.
12
+ #
13
+ # @example Check the gem version
14
+ # puts GLogin::VERSION
15
+ # # => "0.17.0"
16
+ #
17
+ # @example Version comparison
18
+ # if Gem::Version.new(GLogin::VERSION) >= Gem::Version.new('0.1.0')
19
+ # puts "Using GLogin version 0.1.0 or newer"
20
+ # end
21
+ VERSION = '0.17.0'
30
22
  end
data/lib/glogin.rb CHANGED
@@ -1,34 +1,39 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- #
4
- # Copyright (c) 2017-2024 Yegor Bugayenko
5
- #
6
- # Permission is hereby granted, free of charge, to any person obtaining a copy
7
- # of this software and associated documentation files (the 'Software'), to deal
8
- # in the Software without restriction, including without limitation the rights
9
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- # copies of the Software, and to permit persons to whom the Software is
11
- # furnished to do so, subject to the following conditions:
12
- #
13
- # The above copyright notice and this permission notice shall be included in all
14
- # copies or substantial portions of the Software.
15
- #
16
- # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
19
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- # SOFTWARE.
3
+ # SPDX-FileCopyrightText: Copyright (c) 2017-2025 Yegor Bugayenko
4
+ # SPDX-License-Identifier: MIT
23
5
 
24
- require 'nokogiri'
25
- require_relative 'glogin/version'
26
6
  require_relative 'glogin/auth'
27
7
  require_relative 'glogin/cookie'
8
+ require_relative 'glogin/version'
28
9
 
29
10
  # GLogin main module.
11
+ #
12
+ # GLogin is a Ruby gem that provides OAuth integration with GitHub. It simplifies
13
+ # the process of authenticating users through GitHub and managing their sessions
14
+ # using secure cookies.
15
+ #
16
+ # @example Basic usage with Sinatra
17
+ # require 'sinatra'
18
+ # require 'glogin'
19
+ #
20
+ # configure do
21
+ # set :glogin, GLogin::Auth.new(
22
+ # ENV['GITHUB_CLIENT_ID'],
23
+ # ENV['GITHUB_CLIENT_SECRET'],
24
+ # 'http://localhost:4567/auth'
25
+ # )
26
+ # end
27
+ #
28
+ # get '/auth' do
29
+ # user = settings.glogin.user(params[:code])
30
+ # cookie = GLogin::Cookie::Open.new(user, ENV['ENCRYPTION_SECRET'])
31
+ # response.set_cookie('glogin', cookie.to_s)
32
+ # redirect '/'
33
+ # end
34
+ #
30
35
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
31
- # Copyright:: Copyright (c) 2017-2024 Yegor Bugayenko
36
+ # Copyright:: Copyright (c) 2017-2025 Yegor Bugayenko
32
37
  # License:: MIT
33
38
  module GLogin
34
39
  end
data/logo.svg CHANGED
@@ -16,4 +16,4 @@
16
16
  </g>
17
17
  </g>
18
18
  </g>
19
- </svg>
19
+ </svg>
@@ -1,29 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- #
4
- # Copyright (c) 2017-2024 Yegor Bugayenko
5
- #
6
- # Permission is hereby granted, free of charge, to any person obtaining a copy
7
- # of this software and associated documentation files (the 'Software'), to deal
8
- # in the Software without restriction, including without limitation the rights
9
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- # copies of the Software, and to permit persons to whom the Software is
11
- # furnished to do so, subject to the following conditions:
12
- #
13
- # The above copyright notice and this permission notice shall be included in all
14
- # copies or substantial portions of the Software.
15
- #
16
- # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
19
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- # SOFTWARE.
3
+ # SPDX-FileCopyrightText: Copyright (c) 2017-2025 Yegor Bugayenko
4
+ # SPDX-License-Identifier: MIT
23
5
 
24
- require 'minitest/autorun'
25
- require 'webmock/minitest'
26
6
  require_relative '../../lib/glogin/cookie'
7
+ require_relative '../test__helper'
27
8
 
28
9
  class TestAuth < Minitest::Test
29
10
  def test_authenticate_via_https
@@ -62,21 +43,21 @@ class TestAuth < Minitest::Test
62
43
  def test_failed_authentication
63
44
  auth = GLogin::Auth.new('1234', '4433', 'https://example.org')
64
45
  stub_request(:post, 'https://github.com/login/oauth/access_token').to_return(status: 401)
65
- e = assert_raises { auth.user('437849732894732') }
66
- assert(e.message.include?('with code "43784***'))
46
+ e = assert_raises(StandardError) { auth.user('437849732894732') }
47
+ assert_includes(e.message, 'with code "43784***')
67
48
  end
68
49
 
69
50
  def test_broken_json
70
51
  auth = GLogin::Auth.new('1234', '4433', 'https://example.org')
71
52
  stub_request(:post, 'https://github.com/login/oauth/access_token').to_return(body: 'Hello!')
72
- e = assert_raises { auth.user('47839893') }
73
- assert(e.message.include?('unexpected token'), e)
53
+ e = assert_raises(StandardError) { auth.user('47839893') }
54
+ assert_includes(e.message, 'unexpected', e)
74
55
  end
75
56
 
76
57
  def test_no_token_in_json
77
58
  auth = GLogin::Auth.new('1234', '4433', 'https://example.org')
78
59
  stub_request(:post, 'https://github.com/login/oauth/access_token').to_return(body: '{}')
79
- e = assert_raises { auth.user('47839893') }
80
- assert(e.message.include?('There is no \'access_token\''), e)
60
+ e = assert_raises(StandardError) { auth.user('47839893') }
61
+ assert_includes(e.message, 'There is no \'access_token\'', e)
81
62
  end
82
63
  end
@@ -1,29 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- #
4
- # Copyright (c) 2017-2024 Yegor Bugayenko
5
- #
6
- # Permission is hereby granted, free of charge, to any person obtaining a copy
7
- # of this software and associated documentation files (the 'Software'), to deal
8
- # in the Software without restriction, including without limitation the rights
9
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- # copies of the Software, and to permit persons to whom the Software is
11
- # furnished to do so, subject to the following conditions:
12
- #
13
- # The above copyright notice and this permission notice shall be included in all
14
- # copies or substantial portions of the Software.
15
- #
16
- # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
19
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- # SOFTWARE.
3
+ # SPDX-FileCopyrightText: Copyright (c) 2017-2025 Yegor Bugayenko
4
+ # SPDX-License-Identifier: MIT
23
5
 
24
- require 'minitest/autorun'
25
6
  require 'base64'
26
7
  require_relative '../../lib/glogin/codec'
8
+ require_relative '../test__helper'
27
9
 
28
10
  class TestCodec < Minitest::Test
29
11
  def test_encodes_and_decodes
@@ -48,10 +30,18 @@ class TestCodec < Minitest::Test
48
30
  end
49
31
  end
50
32
 
33
+ def test_decrypts_broken_base58
34
+ %w[abc0 abcO abcl abcI].each do |t|
35
+ assert_raises GLogin::Codec::DecodingError do
36
+ GLogin::Codec.new('some-key').decrypt(t)
37
+ end
38
+ end
39
+ end
40
+
51
41
  def test_encrypts_into_plain_string
52
42
  text = GLogin::Codec.new('6hFGrte5LLmwi').encrypt("K&j\n\n\tuIpwp00{]=")
53
- assert(text =~ /^[a-zA-Z0-9]+$/, text)
54
- assert(!text.include?("\n"), text)
43
+ assert_match(/^[a-zA-Z0-9]+$/, text, text)
44
+ refute_includes(text, "\n", text)
55
45
  end
56
46
 
57
47
  def test_encrypts_using_base64
@@ -1,28 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- #
4
- # Copyright (c) 2017-2024 Yegor Bugayenko
5
- #
6
- # Permission is hereby granted, free of charge, to any person obtaining a copy
7
- # of this software and associated documentation files (the 'Software'), to deal
8
- # in the Software without restriction, including without limitation the rights
9
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- # copies of the Software, and to permit persons to whom the Software is
11
- # furnished to do so, subject to the following conditions:
12
- #
13
- # The above copyright notice and this permission notice shall be included in all
14
- # copies or substantial portions of the Software.
15
- #
16
- # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
19
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- # SOFTWARE.
3
+ # SPDX-FileCopyrightText: Copyright (c) 2017-2025 Yegor Bugayenko
4
+ # SPDX-License-Identifier: MIT
23
5
 
24
- require 'minitest/autorun'
25
6
  require_relative '../../lib/glogin/cookie'
7
+ require_relative '../test__helper'
26
8
 
27
9
  class TestCookie < Minitest::Test
28
10
  def test_encrypts_and_decrypts
@@ -38,8 +20,8 @@ class TestCookie < Minitest::Test
38
20
  ).to_s,
39
21
  secret
40
22
  ).to_user
41
- assert_equal(user['login'], 'yegor256')
42
- assert_equal(user['avatar_url'], 'https://avatars1.githubusercontent.com/u/526301')
23
+ assert_equal('yegor256', user['login'])
24
+ assert_equal('https://avatars1.githubusercontent.com/u/526301', user['avatar_url'])
43
25
  end
44
26
 
45
27
  def test_encrypts_and_decrypts_with_context
@@ -54,18 +36,18 @@ class TestCookie < Minitest::Test
54
36
  secret,
55
37
  context
56
38
  ).to_user
57
- assert_equal(user['id'], '123')
58
- assert_equal(user['login'], 'jeffrey')
59
- assert_equal(user['avatar_url'], '#')
39
+ assert_equal('123', user['id'])
40
+ assert_equal('jeffrey', user['login'])
41
+ assert_equal('#', user['avatar_url'])
60
42
  end
61
43
 
62
44
  def test_decrypts_in_test_mode
63
45
  user = GLogin::Cookie::Closed.new(
64
46
  '123|test|http://example.com', ''
65
47
  ).to_user
66
- assert_equal(user['id'], '123')
67
- assert_equal(user['login'], 'test')
68
- assert_equal(user['avatar_url'], 'http://example.com')
48
+ assert_equal('123', user['id'])
49
+ assert_equal('test', user['login'])
50
+ assert_equal('http://example.com', user['avatar_url'])
69
51
  end
70
52
 
71
53
  def test_decrypts_in_test_mode_with_context
data/test/test__helper.rb CHANGED
@@ -1,30 +1,32 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- #
4
- # Copyright (c) 2017-2024 Yegor Bugayenko
5
- #
6
- # Permission is hereby granted, free of charge, to any person obtaining a copy
7
- # of this software and associated documentation files (the 'Software'), to deal
8
- # in the Software without restriction, including without limitation the rights
9
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- # copies of the Software, and to permit persons to whom the Software is
11
- # furnished to do so, subject to the following conditions:
12
- #
13
- # The above copyright notice and this permission notice shall be included in all
14
- # copies or substantial portions of the Software.
15
- #
16
- # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
19
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- # SOFTWARE.
3
+ # SPDX-FileCopyrightText: Copyright (c) 2017-2025 Yegor Bugayenko
4
+ # SPDX-License-Identifier: MIT
23
5
 
24
6
  $stdout.sync = true
25
7
 
26
8
  require 'simplecov'
27
- SimpleCov.start
9
+ require 'simplecov-cobertura'
10
+ unless SimpleCov.running || ENV['PICKS']
11
+ SimpleCov.command_name('test')
12
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new(
13
+ [
14
+ SimpleCov::Formatter::HTMLFormatter,
15
+ SimpleCov::Formatter::CoberturaFormatter
16
+ ]
17
+ )
18
+ SimpleCov.minimum_coverage 100
19
+ SimpleCov.minimum_coverage_by_file 95
20
+ SimpleCov.start do
21
+ add_filter 'test/'
22
+ add_filter 'vendor/'
23
+ add_filter 'target/'
24
+ track_files 'lib/**/*.rb'
25
+ track_files '*.rb'
26
+ end
27
+ end
28
28
 
29
29
  require 'minitest/autorun'
30
- require_relative '../lib/glogin'
30
+ require 'minitest/reporters'
31
+ require 'webmock/minitest'
32
+ Minitest::Reporters.use! [Minitest::Reporters::SpecReporter.new]
data/test/test_glogin.rb CHANGED
@@ -1,32 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- #
4
- # Copyright (c) 2017-2024 Yegor Bugayenko
5
- #
6
- # Permission is hereby granted, free of charge, to any person obtaining a copy
7
- # of this software and associated documentation files (the 'Software'), to deal
8
- # in the Software without restriction, including without limitation the rights
9
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- # copies of the Software, and to permit persons to whom the Software is
11
- # furnished to do so, subject to the following conditions:
12
- #
13
- # The above copyright notice and this permission notice shall be included in all
14
- # copies or substantial portions of the Software.
15
- #
16
- # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
19
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- # SOFTWARE.
3
+ # SPDX-FileCopyrightText: Copyright (c) 2017-2025 Yegor Bugayenko
4
+ # SPDX-License-Identifier: MIT
23
5
 
24
- require 'minitest/autorun'
25
6
  require_relative '../lib/glogin'
7
+ require_relative 'test__helper'
26
8
 
27
9
  # GLogin main module test.
28
10
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
29
- # Copyright:: Copyright (c) 2017-2024 Yegor Bugayenko
11
+ # Copyright:: Copyright (c) 2017-2025 Yegor Bugayenko
30
12
  # License:: MIT
31
13
  class TestGLogin < Minitest::Test
32
14
  def test_basic