glogin 0.16.5 → 0.17.1

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.
@@ -1,40 +0,0 @@
1
- # Copyright (c) 2017-2025 Yegor Bugayenko
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the 'Software'), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in all
11
- # copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
- # SOFTWARE.
20
- ---
21
- name: codecov
22
- 'on':
23
- push:
24
- branches:
25
- - master
26
- jobs:
27
- codecov:
28
- runs-on: ubuntu-24.04
29
- steps:
30
- - uses: actions/checkout@v4
31
- - uses: ruby/setup-ruby@v1
32
- with:
33
- ruby-version: 2.7
34
- - run: bundle update
35
- - run: bundle exec rake
36
- - uses: codecov/codecov-action@v5
37
- with:
38
- token: ${{ secrets.CODECOV_TOKEN }}
39
- files: coverage/.resultset.json
40
- fail_ci_if_error: true
@@ -1,30 +0,0 @@
1
- # Copyright (c) 2017-2025 Yegor Bugayenko
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the 'Software'), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in all
11
- # copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
- # SOFTWARE.
20
- ---
21
- name: copyrights
22
- 'on':
23
- push:
24
- pull_request:
25
- jobs:
26
- copyrights:
27
- runs-on: ubuntu-24.04
28
- steps:
29
- - uses: actions/checkout@v4
30
- - uses: yegor256/copyrights-action@0.0.8
@@ -1,38 +0,0 @@
1
- # Copyright (c) 2017-2025 Yegor Bugayenko
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the 'Software'), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in all
11
- # copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
- # SOFTWARE.
20
- ---
21
- name: markdown-lint
22
- 'on':
23
- push:
24
- branches:
25
- - master
26
- pull_request:
27
- branches:
28
- - master
29
- paths-ignore: ['paper/**', 'sandbox/**']
30
- concurrency:
31
- group: markdown-lint-${{ github.ref }}
32
- cancel-in-progress: true
33
- jobs:
34
- markdown-lint:
35
- runs-on: ubuntu-24.04
36
- steps:
37
- - uses: actions/checkout@v4
38
- - uses: articulate/actions-markdownlint@v1
@@ -1,34 +0,0 @@
1
- # Copyright (c) 2017-2025 Yegor Bugayenko
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the 'Software'), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in all
11
- # copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
- # SOFTWARE.
20
- ---
21
- name: pdd
22
- 'on':
23
- push:
24
- branches:
25
- - master
26
- pull_request:
27
- branches:
28
- - master
29
- jobs:
30
- pdd:
31
- runs-on: ubuntu-24.04
32
- steps:
33
- - uses: actions/checkout@v4
34
- - uses: volodya-lombrozo/pdd-action@master
@@ -1,43 +0,0 @@
1
- # Copyright (c) 2017-2025 Yegor Bugayenko
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the 'Software'), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in all
11
- # copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
- # SOFTWARE.
20
- ---
21
- name: rake
22
- 'on':
23
- push:
24
- branches:
25
- - master
26
- pull_request:
27
- branches:
28
- - master
29
- jobs:
30
- rake:
31
- name: test
32
- strategy:
33
- matrix:
34
- os: [ubuntu-24.04, macos-15]
35
- ruby: [2.7, 3.3]
36
- runs-on: ${{ matrix.os }}
37
- steps:
38
- - uses: actions/checkout@v4
39
- - uses: ruby/setup-ruby@v1
40
- with:
41
- ruby-version: ${{ matrix.ruby }}
42
- - run: bundle update
43
- - run: bundle exec rake
@@ -1,30 +0,0 @@
1
- # Copyright (c) 2017-2025 Yegor Bugayenko
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the 'Software'), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in all
11
- # copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
- # SOFTWARE.
20
- ---
21
- name: xcop
22
- 'on':
23
- push:
24
- pull_request:
25
- jobs:
26
- xcop:
27
- runs-on: ubuntu-24.04
28
- steps:
29
- - uses: actions/checkout@v4
30
- - uses: g4s8/xcop-action@master
data/.gitignore DELETED
@@ -1,7 +0,0 @@
1
- coverage/
2
- Gemfile.lock
3
- .idea/
4
- *.gem
5
- .bundle/
6
- .DS_Store
7
- rdoc/
data/.pdd DELETED
@@ -1,7 +0,0 @@
1
- --source=.
2
- --verbose
3
- --exclude target/**/*
4
- --exclude coverage/**/*
5
- --rule min-words:20
6
- --rule min-estimate:15
7
- --rule max-estimate:90
data/.rubocop.yml DELETED
@@ -1,52 +0,0 @@
1
- # Copyright (c) 2017-2025 Yegor Bugayenko
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the 'Software'), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in all
11
- # copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
- # SOFTWARE.
20
- ---
21
- AllCops:
22
- Exclude:
23
- - 'bin/**/*'
24
- - 'assets/**/*'
25
- DisplayCopNames: true
26
- TargetRubyVersion: 2.3
27
- SuggestExtensions: false
28
- NewCops: enable
29
- require:
30
- - rubocop-minitest
31
- - rubocop-performance
32
-
33
- Minitest/EmptyLineBeforeAssertionMethods:
34
- Enabled: false
35
- Gemspec/RequiredRubyVersion:
36
- Enabled: false
37
- Metrics/MethodLength:
38
- Enabled: false
39
- Style/ClassAndModuleChildren:
40
- Enabled: false
41
- Layout/MultilineMethodCallIndentation:
42
- Enabled: false
43
- Metrics/AbcSize:
44
- Enabled: false
45
- Metrics/BlockLength:
46
- Max: 30
47
- Metrics/CyclomaticComplexity:
48
- Max: 20
49
- Metrics/PerceivedComplexity:
50
- Max: 20
51
- Layout/EmptyLineAfterGuardClause:
52
- Enabled: false
data/.rultor.yml DELETED
@@ -1,42 +0,0 @@
1
- # Copyright (c) 2017-2025 Yegor Bugayenko
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the 'Software'), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in all
11
- # copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
- # SOFTWARE.
20
- ---
21
- docker:
22
- image: yegor256/rultor-ruby
23
- assets:
24
- rubygems.yml: yegor256/home#assets/rubygems.yml
25
- install: |
26
- pdd -f /dev/null
27
- bundle install --no-color
28
- release:
29
- pre: false
30
- script: |-
31
- [[ "${tag}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || exit -1
32
- bundle exec rake
33
- rm -rf *.gem
34
- sed -i "s/0\.0\.0/${tag}/g" lib/glogin/version.rb
35
- git add lib/glogin/version.rb
36
- git commit -m "version set to ${tag}"
37
- gem build glogin.gemspec
38
- chmod 0600 ../rubygems.yml
39
- gem push *.gem --config-file ../rubygems.yml
40
- merge:
41
- script: |-
42
- bundle exec rake
data/.simplecov DELETED
@@ -1,41 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- #
4
- # Copyright (c) 2017-2025 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.
23
-
24
- if Gem.win_platform?
25
- SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
26
- SimpleCov::Formatter::HTMLFormatter
27
- ]
28
- SimpleCov.start do
29
- add_filter '/test/'
30
- add_filter '/features/'
31
- end
32
- else
33
- SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new(
34
- [SimpleCov::Formatter::HTMLFormatter]
35
- )
36
- SimpleCov.start do
37
- add_filter '/test/'
38
- add_filter '/features/'
39
- minimum_coverage 20
40
- end
41
- end
data/renovate.json DELETED
@@ -1,6 +0,0 @@
1
- {
2
- "$schema": "https://docs.renovatebot.com/renovate-schema.json",
3
- "extends": [
4
- "config:base"
5
- ]
6
- }
@@ -1,82 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- #
4
- # Copyright (c) 2017-2025 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.
23
-
24
- require 'minitest/autorun'
25
- require 'webmock/minitest'
26
- require_relative '../../lib/glogin/cookie'
27
-
28
- class TestAuth < Minitest::Test
29
- def test_authenticate_via_https
30
- auth = GLogin::Auth.new('1234', '4433', 'https://example.org')
31
- stub_request(:post, 'https://github.com/login/oauth/access_token').to_return(
32
- body: {
33
- access_token: 'some-token'
34
- }.to_json
35
- )
36
- stub_request(:get, 'https://api.github.com/user').to_return(
37
- body: {
38
- auth_code: '437849732894732',
39
- login: 'yegor256'
40
- }.to_json
41
- )
42
- user = auth.user('437849732894732')
43
- assert_equal('yegor256', user['login'])
44
- end
45
-
46
- def test_login_uri
47
- auth = GLogin::Auth.new(
48
- 'client_id', 'client_secret', 'http://www.example.com/github-oauth'
49
- )
50
- assert(
51
- auth.login_uri.start_with?(
52
- 'https://github.com/login/oauth/authorize'
53
- )
54
- )
55
- end
56
-
57
- def test_get_fake_user
58
- auth = GLogin::Auth.new('99999', '', 'http://www.example.com/github-oauth')
59
- assert_equal('yegor256', auth.user('1234567890')['login'])
60
- end
61
-
62
- def test_failed_authentication
63
- auth = GLogin::Auth.new('1234', '4433', 'https://example.org')
64
- stub_request(:post, 'https://github.com/login/oauth/access_token').to_return(status: 401)
65
- e = assert_raises(StandardError) { auth.user('437849732894732') }
66
- assert_includes(e.message, 'with code "43784***')
67
- end
68
-
69
- def test_broken_json
70
- auth = GLogin::Auth.new('1234', '4433', 'https://example.org')
71
- stub_request(:post, 'https://github.com/login/oauth/access_token').to_return(body: 'Hello!')
72
- e = assert_raises(StandardError) { auth.user('47839893') }
73
- assert_includes(e.message, 'unexpected token', e)
74
- end
75
-
76
- def test_no_token_in_json
77
- auth = GLogin::Auth.new('1234', '4433', 'https://example.org')
78
- stub_request(:post, 'https://github.com/login/oauth/access_token').to_return(body: '{}')
79
- e = assert_raises(StandardError) { auth.user('47839893') }
80
- assert_includes(e.message, 'There is no \'access_token\'', e)
81
- end
82
- end
@@ -1,89 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- #
4
- # Copyright (c) 2017-2025 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.
23
-
24
- require 'minitest/autorun'
25
- require 'base64'
26
- require_relative '../../lib/glogin/codec'
27
-
28
- class TestCodec < Minitest::Test
29
- def test_encodes_and_decodes
30
- text = 'This is the text, дорогой товарищ'
31
- assert_equal(
32
- text,
33
- Base64.decode64(Base64.encode64(text)).force_encoding('UTF-8')
34
- )
35
- end
36
-
37
- def test_encrypts_and_decrypts
38
- crypt = GLogin::Codec.new('this is the secret key!')
39
- text = 'This is the text, товарищ'
40
- assert_equal(text, crypt.decrypt(crypt.encrypt(text)))
41
- end
42
-
43
- def test_decrypts_with_invalid_password
44
- assert_raises GLogin::Codec::DecodingError do
45
- GLogin::Codec.new('the wrong key').decrypt(
46
- GLogin::Codec.new('the right key').encrypt('the text')
47
- )
48
- end
49
- end
50
-
51
- def test_decrypts_broken_base58
52
- %w[abc0 abcO abcl abcI].each do |t|
53
- assert_raises GLogin::Codec::DecodingError do
54
- GLogin::Codec.new('some-key').decrypt(t)
55
- end
56
- end
57
- end
58
-
59
- def test_encrypts_into_plain_string
60
- text = GLogin::Codec.new('6hFGrte5LLmwi').encrypt("K&j\n\n\tuIpwp00{]=")
61
- assert_match(/^[a-zA-Z0-9]+$/, text, text)
62
- refute_includes(text, "\n", text)
63
- end
64
-
65
- def test_encrypts_using_base64
66
- codec = GLogin::Codec.new('6hFGrte5LLmwi', base64: true)
67
- text = 'Hello, world!'
68
- enc = codec.encrypt(text)
69
- assert_equal(text, codec.decrypt(enc))
70
- end
71
-
72
- def test_decrypts_broken_text
73
- assert_raises GLogin::Codec::DecodingError do
74
- GLogin::Codec.new('the key').decrypt('этот текст не был зашифрован')
75
- end
76
- end
77
-
78
- def test_decrypts_broken_text_with_empty_key
79
- assert_raises GLogin::Codec::DecodingError do
80
- GLogin::Codec.new('key').decrypt('')
81
- end
82
- end
83
-
84
- def test_encrypts_and_decrypts_with_empty_key
85
- crypt = GLogin::Codec.new
86
- text = 'This is the text, дорогой друг!'
87
- assert_equal(text, crypt.decrypt(crypt.encrypt(text)))
88
- end
89
- end
@@ -1,106 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- #
4
- # Copyright (c) 2017-2025 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.
23
-
24
- require 'minitest/autorun'
25
- require_relative '../../lib/glogin/cookie'
26
-
27
- class TestCookie < Minitest::Test
28
- def test_encrypts_and_decrypts
29
- secret = 'this&84-- (832=_'
30
- user = GLogin::Cookie::Closed.new(
31
- GLogin::Cookie::Open.new(
32
- JSON.parse(
33
- "{\"id\":123,\"node_id\":\"how are you?\",
34
- \"login\":\"yegor256\",
35
- \"avatar_url\":\"https://avatars1.githubusercontent.com/u/526301\"}"
36
- ),
37
- secret
38
- ).to_s,
39
- secret
40
- ).to_user
41
- assert_equal('yegor256', user['login'])
42
- assert_equal('https://avatars1.githubusercontent.com/u/526301', user['avatar_url'])
43
- end
44
-
45
- def test_encrypts_and_decrypts_with_context
46
- secret = 'kfdj7hjsywhs6hjshr7shsw990s'
47
- context = '127.0.0.1'
48
- user = GLogin::Cookie::Closed.new(
49
- GLogin::Cookie::Open.new(
50
- JSON.parse('{"id":"123","login":"jeffrey","avatar_url":"#"}'),
51
- secret,
52
- context
53
- ).to_s,
54
- secret,
55
- context
56
- ).to_user
57
- assert_equal('123', user['id'])
58
- assert_equal('jeffrey', user['login'])
59
- assert_equal('#', user['avatar_url'])
60
- end
61
-
62
- def test_decrypts_in_test_mode
63
- user = GLogin::Cookie::Closed.new(
64
- '123|test|http://example.com', ''
65
- ).to_user
66
- assert_equal('123', user['id'])
67
- assert_equal('test', user['login'])
68
- assert_equal('http://example.com', user['avatar_url'])
69
- end
70
-
71
- def test_decrypts_in_test_mode_with_context
72
- user = GLogin::Cookie::Closed.new(
73
- '123', '', 'some context'
74
- ).to_user
75
- assert_equal('123', user['id'])
76
- assert_nil(user['login'])
77
- assert_nil(user['avatar_url'])
78
- end
79
-
80
- def test_fails_on_broken_text
81
- assert_raises GLogin::Codec::DecodingError do
82
- GLogin::Cookie::Closed.new(
83
- GLogin::Cookie::Open.new(
84
- JSON.parse('{"login":"x","avatar_url":"x","id":"1"}'),
85
- 'secret-1'
86
- ).to_s,
87
- 'secret-2'
88
- ).to_user
89
- end
90
- end
91
-
92
- def test_fails_on_wrong_context
93
- secret = 'fdjruewoijs789fdsufds89f7ds89fs'
94
- assert_raises GLogin::Codec::DecodingError do
95
- GLogin::Cookie::Closed.new(
96
- GLogin::Cookie::Open.new(
97
- JSON.parse('{"login":"x","avatar_url":"x","id":""}'),
98
- secret,
99
- 'context-1'
100
- ).to_s,
101
- secret,
102
- 'context-2'
103
- ).to_user
104
- end
105
- end
106
- end