zold 0.31.10 → 0.32.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.
- checksums.yaml +4 -4
- data/Dockerfile +11 -27
- data/Gemfile +21 -33
- data/Gemfile.lock +181 -126
- data/Guardfile +0 -0
- data/INSTALL.md +80 -59
- data/LICENSE.txt +1 -1
- data/LICENSES/MIT.txt +21 -0
- data/README.md +183 -154
- data/REUSE.toml +40 -0
- data/Rakefile +4 -38
- data/bin/zold +7 -37
- data/deploy.sh +4 -22
- data/lib/zold/age.rb +3 -20
- data/lib/zold/amount.rb +3 -20
- data/lib/zold/cached_wallets.rb +3 -20
- data/lib/zold/commands/alias.rb +4 -21
- data/lib/zold/commands/args.rb +4 -21
- data/lib/zold/commands/calculate.rb +5 -22
- data/lib/zold/commands/clean.rb +6 -23
- data/lib/zold/commands/create.rb +5 -22
- data/lib/zold/commands/diff.rb +5 -22
- data/lib/zold/commands/fetch.rb +6 -23
- data/lib/zold/commands/invoice.rb +5 -22
- data/lib/zold/commands/list.rb +5 -22
- data/lib/zold/commands/merge.rb +7 -24
- data/lib/zold/commands/next.rb +5 -22
- data/lib/zold/commands/node.rb +4 -21
- data/lib/zold/commands/pay.rb +6 -23
- data/lib/zold/commands/propagate.rb +5 -22
- data/lib/zold/commands/pull.rb +5 -22
- data/lib/zold/commands/push.rb +5 -22
- data/lib/zold/commands/remote.rb +7 -24
- data/lib/zold/commands/remove.rb +5 -22
- data/lib/zold/commands/routines/audit.rb +4 -21
- data/lib/zold/commands/routines/gc.rb +6 -23
- data/lib/zold/commands/routines/reconcile.rb +5 -22
- data/lib/zold/commands/routines/reconnect.rb +4 -21
- data/lib/zold/commands/routines/retire.rb +4 -21
- data/lib/zold/commands/routines/spread.rb +5 -22
- data/lib/zold/commands/routines.rb +3 -20
- data/lib/zold/commands/show.rb +5 -22
- data/lib/zold/commands/taxes.rb +5 -22
- data/lib/zold/commands/thread_badge.rb +3 -20
- data/lib/zold/copies.rb +6 -25
- data/lib/zold/dir_items.rb +3 -20
- data/lib/zold/endless.rb +5 -22
- data/lib/zold/gem.rb +3 -20
- data/lib/zold/hands.rb +6 -23
- data/lib/zold/head.rb +4 -21
- data/lib/zold/hexnum.rb +3 -20
- data/lib/zold/http.rb +3 -20
- data/lib/zold/hungry_wallets.rb +6 -23
- data/lib/zold/id.rb +3 -20
- data/lib/zold/json_page.rb +5 -22
- data/lib/zold/key.rb +3 -20
- data/lib/zold/metronome.rb +5 -22
- data/lib/zold/node/async_entrance.rb +6 -23
- data/lib/zold/node/entrance.rb +7 -24
- data/lib/zold/node/farm.rb +5 -22
- data/lib/zold/node/farmers.rb +15 -32
- data/lib/zold/node/front.rb +6 -23
- data/lib/zold/node/journaled_pipeline.rb +8 -25
- data/lib/zold/node/nodup_entrance.rb +6 -23
- data/lib/zold/node/nospam_entrance.rb +6 -23
- data/lib/zold/node/pipeline.rb +6 -23
- data/lib/zold/node/safe_entrance.rb +4 -22
- data/lib/zold/node/soft_error.rb +3 -20
- data/lib/zold/node/spread_entrance.rb +5 -22
- data/lib/zold/node/sync_entrance.rb +5 -22
- data/lib/zold/node/trace.rb +3 -20
- data/lib/zold/patch.rb +6 -23
- data/lib/zold/prefixes.rb +3 -20
- data/lib/zold/remotes.rb +5 -22
- data/lib/zold/signature.rb +3 -20
- data/lib/zold/size.rb +3 -20
- data/lib/zold/sync_wallets.rb +5 -22
- data/lib/zold/tax.rb +4 -21
- data/lib/zold/thread_pool.rb +4 -21
- data/lib/zold/tree_wallets.rb +3 -20
- data/lib/zold/txn.rb +4 -21
- data/lib/zold/txns.rb +4 -21
- data/lib/zold/upgrades.rb +4 -21
- data/lib/zold/verbose_thread.rb +5 -22
- data/lib/zold/version.rb +4 -21
- data/lib/zold/version_file.rb +4 -21
- data/lib/zold/wallet.rb +6 -23
- data/lib/zold/wallets.rb +5 -23
- data/lib/zold.rb +3 -21
- data/resources/banned-wallets.log +6 -6
- data/upgrades/2.rb +3 -20
- data/upgrades/delete_banned_wallets.rb +3 -20
- data/upgrades/move_wallets_into_tree.rb +3 -20
- data/upgrades/protocol_up.rb +3 -20
- data/upgrades/rename_foreign_wallets.rb +3 -20
- data/views/journal.haml +25 -0
- data/views/layout.haml +25 -0
- data/views/wallet.haml +25 -0
- data/zold.gemspec +6 -22
- metadata +26 -174
- data/.0pdd.yml +0 -29
- data/.gitattributes +0 -9
- data/.github/workflows/actionlint.yml +0 -41
- data/.github/workflows/codecov.yml +0 -40
- data/.github/workflows/copyrights.yml +0 -30
- data/.github/workflows/pdd.yml +0 -34
- data/.github/workflows/rake.yml +0 -45
- data/.github/workflows/xcop.yml +0 -30
- data/.github/workflows/yamllint.yml +0 -34
- data/.gitignore +0 -12
- data/.pdd +0 -7
- data/.rubocop.yml +0 -70
- data/.ruby-version +0 -1
- data/.rultor.yml +0 -57
- data/.simplecov +0 -36
- data/cucumber.yml +0 -23
- data/features/cli.feature +0 -16
- data/features/gem_package.feature +0 -26
- data/features/step_definitions/steps.rb +0 -84
- data/features/support/env.rb +0 -26
- data/fixtures/448b451bc62e8e16.z +0 -1005
- data/fixtures/id_rsa +0 -51
- data/fixtures/id_rsa-2 +0 -51
- data/fixtures/id_rsa-2.pub +0 -1
- data/fixtures/id_rsa.pub +0 -1
- data/fixtures/keys/1.pub +0 -1
- data/fixtures/keys/2 +0 -51
- data/fixtures/keys/2.pub +0 -1
- data/fixtures/merge/asserts.rb +0 -36
- data/fixtures/merge/id_rsa +0 -51
- data/fixtures/merge/id_rsa.pub +0 -1
- data/fixtures/merge/into_no_wallet/assert.rb +0 -25
- data/fixtures/merge/into_no_wallet/copies/0123456789abcdef/1.zc +0 -6
- data/fixtures/merge/into_no_wallet/copies/0123456789abcdef/scores.zc +0 -1
- data/fixtures/merge/into_no_wallet/opts +0 -1
- data/fixtures/merge/legacy_negatives_stay/0123456789abcdef.z +0 -6
- data/fixtures/merge/legacy_negatives_stay/assert.rb +0 -25
- data/fixtures/merge/legacy_negatives_stay/copies/0123456789abcdef/1.zc +0 -6
- data/fixtures/merge/legacy_negatives_stay/copies/0123456789abcdef/scores.zc +0 -1
- data/fixtures/merge/legacy_negatives_stay/opts +0 -2
- data/fixtures/merge/missed_wallets/0000000000000000.z +0 -6
- data/fixtures/merge/missed_wallets/0123456789abcdef.z +0 -6
- data/fixtures/merge/missed_wallets/assert.rb +0 -25
- data/fixtures/merge/missed_wallets/copies/0123456789abcdef/1.zc +0 -8
- data/fixtures/merge/missed_wallets/copies/0123456789abcdef/scores.zc +0 -1
- data/fixtures/merge/missed_wallets/opts +0 -3
- data/fixtures/merge/negative_overwriting/0123456789abcdef.z +0 -6
- data/fixtures/merge/negative_overwriting/146b852f2d9ad984.z +0 -6
- data/fixtures/merge/negative_overwriting/assert.rb +0 -25
- data/fixtures/merge/negative_overwriting/copies/0123456789abcdef/1.zc +0 -6
- data/fixtures/merge/negative_overwriting/copies/0123456789abcdef/scores.zc +0 -1
- data/fixtures/merge/negative_overwriting/opts +0 -2
- data/fixtures/merge/negatives_in_between/0000000000000000.z +0 -6
- data/fixtures/merge/negatives_in_between/0123456789abcdef.z +0 -5
- data/fixtures/merge/negatives_in_between/assert.rb +0 -25
- data/fixtures/merge/negatives_in_between/copies/0123456789abcdef/1.zc +0 -6
- data/fixtures/merge/negatives_in_between/copies/0123456789abcdef/2.zc +0 -7
- data/fixtures/merge/negatives_in_between/copies/0123456789abcdef/3.zc +0 -6
- data/fixtures/merge/negatives_in_between/copies/0123456789abcdef/scores.zc +0 -3
- data/fixtures/merge/negatives_in_between/opts +0 -1
- data/fixtures/merge/random_expenses/0000000000000000.z +0 -6
- data/fixtures/merge/random_expenses/0123456789abcdef.z +0 -6
- data/fixtures/merge/random_expenses/assert.rb +0 -25
- data/fixtures/merge/random_expenses/copies/0123456789abcdef/1.zc +0 -7
- data/fixtures/merge/random_expenses/copies/0123456789abcdef/2.zc +0 -7
- data/fixtures/merge/random_expenses/copies/0123456789abcdef/3.zc +0 -7
- data/fixtures/merge/random_expenses/copies/0123456789abcdef/4.zc +0 -7
- data/fixtures/merge/random_expenses/copies/0123456789abcdef/5.zc +0 -7
- data/fixtures/merge/random_expenses/copies/0123456789abcdef/scores.zc +0 -5
- data/fixtures/merge/random_expenses/opts +0 -1
- data/fixtures/merge/simple_case/0000000000000000.z +0 -6
- data/fixtures/merge/simple_case/0123456789abcdef.z +0 -4
- data/fixtures/merge/simple_case/assert.rb +0 -25
- data/fixtures/merge/simple_case/copies/0123456789abcdef/1.zc +0 -6
- data/fixtures/merge/simple_case/copies/0123456789abcdef/scores.zc +0 -1
- data/fixtures/merge/simple_case/opts +0 -1
- data/fixtures/merge/unconfirmed_income/0123456789abcdef.z +0 -4
- data/fixtures/merge/unconfirmed_income/assert.rb +0 -25
- data/fixtures/merge/unconfirmed_income/copies/0123456789abcdef/1.zc +0 -6
- data/fixtures/merge/unconfirmed_income/copies/0123456789abcdef/scores.zc +0 -1
- data/fixtures/merge/unconfirmed_income/opts +0 -3
- data/fixtures/scripts/_head.sh +0 -89
- data/fixtures/scripts/calculate-scores.sh +0 -22
- data/fixtures/scripts/distribute-wallet.sh +0 -105
- data/fixtures/scripts/print-helps.sh +0 -27
- data/fixtures/scripts/pull-on-start.sh +0 -52
- data/fixtures/scripts/push-and-pull.sh +0 -63
- data/fixtures/scripts/redeploy-on-upgrade.sh +0 -56
- data/fixtures/scripts/spread-wallets.sh +0 -72
- data/lib/zold/log.rb +0 -139
- data/renovate.json +0 -6
- data/test/commands/routines/test_audit.rb +0 -41
- data/test/commands/routines/test_gc.rb +0 -70
- data/test/commands/routines/test_reconcile.rb +0 -51
- data/test/commands/routines/test_reconnect.rb +0 -46
- data/test/commands/routines/test_retire.rb +0 -40
- data/test/commands/test_alias.rb +0 -76
- data/test/commands/test_calculate.rb +0 -40
- data/test/commands/test_clean.rb +0 -73
- data/test/commands/test_create.rb +0 -50
- data/test/commands/test_diff.rb +0 -61
- data/test/commands/test_fetch.rb +0 -162
- data/test/commands/test_invoice.rb +0 -50
- data/test/commands/test_list.rb +0 -47
- data/test/commands/test_merge.rb +0 -129
- data/test/commands/test_node.rb +0 -68
- data/test/commands/test_pay.rb +0 -221
- data/test/commands/test_propagate.rb +0 -51
- data/test/commands/test_pull.rb +0 -70
- data/test/commands/test_push.rb +0 -93
- data/test/commands/test_remote.rb +0 -265
- data/test/commands/test_remove.rb +0 -66
- data/test/commands/test_show.rb +0 -48
- data/test/commands/test_taxes.rb +0 -76
- data/test/fake_home.rb +0 -104
- data/test/node/fake_entrance.rb +0 -43
- data/test/node/fake_node.rb +0 -105
- data/test/node/test_async_entrance.rb +0 -103
- data/test/node/test_entrance.rb +0 -82
- data/test/node/test_farm.rb +0 -177
- data/test/node/test_farmers.rb +0 -76
- data/test/node/test_front.rb +0 -399
- data/test/node/test_nodup_entrance.rb +0 -49
- data/test/node/test_nospam_entrance.rb +0 -49
- data/test/node/test_safe_entrance.rb +0 -59
- data/test/node/test_spread_entrance.rb +0 -67
- data/test/node/test_sync_entrance.rb +0 -41
- data/test/node/test_trace.rb +0 -36
- data/test/test__helper.rb +0 -112
- data/test/test_age.rb +0 -55
- data/test/test_amount.rb +0 -81
- data/test/test_cached_wallets.rb +0 -73
- data/test/test_copies.rb +0 -145
- data/test/test_dir_items.rb +0 -90
- data/test/test_gem.rb +0 -41
- data/test/test_hands.rb +0 -69
- data/test/test_hexnum.rb +0 -36
- data/test/test_http.rb +0 -225
- data/test/test_hungry_wallets.rb +0 -90
- data/test/test_id.rb +0 -79
- data/test/test_json_page.rb +0 -47
- data/test/test_key.rb +0 -99
- data/test/test_log.rb +0 -49
- data/test/test_metronome.rb +0 -89
- data/test/test_patch.rb +0 -178
- data/test/test_prefixes.rb +0 -49
- data/test/test_remotes.rb +0 -319
- data/test/test_signature.rb +0 -49
- data/test/test_size.rb +0 -39
- data/test/test_sync_wallets.rb +0 -57
- data/test/test_tax.rb +0 -171
- data/test/test_thread_pool.rb +0 -89
- data/test/test_tree_wallets.rb +0 -83
- data/test/test_txn.rb +0 -89
- data/test/test_upgrades.rb +0 -99
- data/test/test_verbose_thread.rb +0 -55
- data/test/test_version.rb +0 -35
- data/test/test_wallet.rb +0 -318
- data/test/test_wallets.rb +0 -85
- data/test/test_zold.rb +0 -99
- data/test/upgrades/test_delete_banned_wallets.rb +0 -47
- data/test/upgrades/test_protocol_up.rb +0 -42
data/test/test_hands.rb
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# Copyright (c) 2018-2024 Zerocracy
|
|
4
|
-
#
|
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
# of this software and associated documentation files (the 'Software'), to deal
|
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
# furnished to do so, subject to the following conditions:
|
|
11
|
-
#
|
|
12
|
-
# The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
# copies or substantial portions of the Software.
|
|
14
|
-
#
|
|
15
|
-
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
# SOFTWARE.
|
|
22
|
-
|
|
23
|
-
require 'minitest/autorun'
|
|
24
|
-
require 'concurrent'
|
|
25
|
-
require_relative 'test__helper'
|
|
26
|
-
require_relative '../lib/zold/hands'
|
|
27
|
-
|
|
28
|
-
# Hands test.
|
|
29
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
30
|
-
# Copyright:: Copyright (c) 2018-2024 Zerocracy
|
|
31
|
-
# License:: MIT
|
|
32
|
-
class TestHands < Zold::Test
|
|
33
|
-
def test_runs_in_many_threads
|
|
34
|
-
idx = Concurrent::AtomicFixnum.new
|
|
35
|
-
threads = 50
|
|
36
|
-
Zold::Hands.exec(threads) do
|
|
37
|
-
idx.increment
|
|
38
|
-
end
|
|
39
|
-
assert_equal(threads, idx.value)
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
def test_runs_with_empty_set
|
|
43
|
-
Zold::Hands.exec(5, []) do
|
|
44
|
-
# nothing
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
def test_runs_with_index
|
|
49
|
-
idx = Concurrent::AtomicFixnum.new
|
|
50
|
-
indexes = Set.new
|
|
51
|
-
Zold::Hands.exec(10, %w[a b c]) do |_, i|
|
|
52
|
-
idx.increment
|
|
53
|
-
indexes << i
|
|
54
|
-
end
|
|
55
|
-
assert_equal(3, idx.value)
|
|
56
|
-
assert_equal('0 1 2', indexes.to_a.sort.join(' '))
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
def test_runs_with_exceptions
|
|
60
|
-
assert_raises do
|
|
61
|
-
Zold::Hands.exec(5) do |i|
|
|
62
|
-
if i == 4
|
|
63
|
-
sleep 0.1
|
|
64
|
-
raise 'intended'
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
end
|
data/test/test_hexnum.rb
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# Copyright (c) 2018-2024 Zerocracy
|
|
4
|
-
#
|
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
# of this software and associated documentation files (the 'Software'), to deal
|
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
# furnished to do so, subject to the following conditions:
|
|
11
|
-
#
|
|
12
|
-
# The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
# copies or substantial portions of the Software.
|
|
14
|
-
#
|
|
15
|
-
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
# SOFTWARE.
|
|
22
|
-
|
|
23
|
-
require 'minitest/autorun'
|
|
24
|
-
require_relative '../lib/zold/hexnum'
|
|
25
|
-
|
|
26
|
-
# Hexnum test.
|
|
27
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
28
|
-
# Copyright:: Copyright (c) 2018-2024 Zerocracy
|
|
29
|
-
# License:: MIT
|
|
30
|
-
class TestHexnum < Zold::Test
|
|
31
|
-
def test_prints_and_parses
|
|
32
|
-
[0, 1, 3, 5, 7, 13, 6447, 897_464, -1, -3, -7584, -900_098].each do |n|
|
|
33
|
-
assert_equal(n, Zold::Hexnum.parse(Zold::Hexnum.new(n, 6).to_s).to_i)
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|
data/test/test_http.rb
DELETED
|
@@ -1,225 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# Copyright (c) 2018-2024 Zerocracy
|
|
4
|
-
#
|
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
# of this software and associated documentation files (the 'Software'), to deal
|
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
# furnished to do so, subject to the following conditions:
|
|
11
|
-
#
|
|
12
|
-
# The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
# copies or substantial portions of the Software.
|
|
14
|
-
#
|
|
15
|
-
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
# SOFTWARE.
|
|
22
|
-
|
|
23
|
-
require 'minitest/autorun'
|
|
24
|
-
require 'tmpdir'
|
|
25
|
-
require 'uri'
|
|
26
|
-
require 'webmock/minitest'
|
|
27
|
-
require 'zold/score'
|
|
28
|
-
require 'random-port'
|
|
29
|
-
require_relative 'test__helper'
|
|
30
|
-
require_relative '../lib/zold/http'
|
|
31
|
-
require_relative '../lib/zold/verbose_thread'
|
|
32
|
-
|
|
33
|
-
# Http test.
|
|
34
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
35
|
-
# Copyright:: Copyright (c) 2018-2024 Zerocracy
|
|
36
|
-
# License:: MIT
|
|
37
|
-
class TestHttp < Zold::Test
|
|
38
|
-
def test_pings_broken_uri
|
|
39
|
-
stub_request(:get, 'http://bad-host/').to_return(status: 500)
|
|
40
|
-
res = Zold::Http.new(uri: 'http://bad-host/').get
|
|
41
|
-
assert_equal(500, res.status)
|
|
42
|
-
assert_equal('', res.body)
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def test_pings_with_exception
|
|
46
|
-
stub_request(:get, 'http://exception/').to_return { raise 'Intentionally' }
|
|
47
|
-
res = Zold::Http.new(uri: 'http://exception/').get
|
|
48
|
-
assert_equal(599, res.status)
|
|
49
|
-
assert(res.body.include?('Intentionally'))
|
|
50
|
-
assert(!res.headers['nothing'])
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def test_pings_live_uri
|
|
54
|
-
stub_request(:get, 'http://good-host/').to_return(status: 200)
|
|
55
|
-
res = Zold::Http.new(uri: 'http://good-host/').get
|
|
56
|
-
assert_equal(200, res.status)
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
def test_sends_valid_network_header
|
|
60
|
-
stub_request(:get, 'http://some-host-1/')
|
|
61
|
-
.with(headers: { 'X-Zold-Network' => 'xyz' })
|
|
62
|
-
.to_return(status: 200)
|
|
63
|
-
res = Zold::Http.new(uri: 'http://some-host-1/', network: 'xyz').get
|
|
64
|
-
assert_equal(200, res.status)
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
def test_sends_valid_protocol_header
|
|
68
|
-
stub_request(:get, 'http://some-host-2/')
|
|
69
|
-
.with(headers: { 'X-Zold-Protocol' => Zold::PROTOCOL })
|
|
70
|
-
.to_return(status: 200)
|
|
71
|
-
res = Zold::Http.new(uri: 'http://some-host-2/').get
|
|
72
|
-
assert_equal(200, res.status)
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
def test_terminates_on_timeout
|
|
76
|
-
WebMock.allow_net_connect!
|
|
77
|
-
RandomPort::Pool::SINGLETON.acquire do |port|
|
|
78
|
-
thread = Thread.start do
|
|
79
|
-
Zold::VerboseThread.new(fake_log).run do
|
|
80
|
-
server = TCPServer.new(port)
|
|
81
|
-
server.accept
|
|
82
|
-
sleep 400
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
sleep 0.25
|
|
86
|
-
res = Zold::Http.new(uri: "http://127.0.0.1:#{port}/").get(timeout: 0.1)
|
|
87
|
-
assert_equal(599, res.status, res)
|
|
88
|
-
assert_equal('', res.status_line, res)
|
|
89
|
-
thread.kill
|
|
90
|
-
thread.join
|
|
91
|
-
end
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
def test_doesnt_terminate_on_long_call
|
|
95
|
-
WebMock.allow_net_connect!
|
|
96
|
-
RandomPort::Pool::SINGLETON.acquire do |port|
|
|
97
|
-
thread = Thread.start do
|
|
98
|
-
Zold::VerboseThread.new(fake_log).run do
|
|
99
|
-
server = TCPServer.new(port)
|
|
100
|
-
client = server.accept
|
|
101
|
-
client.puts("HTTP/1.1 200 OK\r\nContent-Length: 4\r\n\r\n")
|
|
102
|
-
sleep 1
|
|
103
|
-
client.puts('Good')
|
|
104
|
-
client.close
|
|
105
|
-
end
|
|
106
|
-
end
|
|
107
|
-
sleep 0.25
|
|
108
|
-
res = Zold::Http.new(uri: "http://127.0.0.1:#{port}/").get(timeout: 2)
|
|
109
|
-
assert_equal(200, res.status, res)
|
|
110
|
-
thread.kill
|
|
111
|
-
thread.join
|
|
112
|
-
end
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
def test_sends_correct_http_headers
|
|
116
|
-
WebMock.allow_net_connect!
|
|
117
|
-
body = ''
|
|
118
|
-
RandomPort::Pool::SINGLETON.acquire do |port|
|
|
119
|
-
latch = Concurrent::CountDownLatch.new(1)
|
|
120
|
-
thread = Thread.start do
|
|
121
|
-
Zold::VerboseThread.new(fake_log).run do
|
|
122
|
-
server = TCPServer.new('127.0.0.1', port)
|
|
123
|
-
latch.count_down
|
|
124
|
-
socket = server.accept
|
|
125
|
-
loop do
|
|
126
|
-
line = socket.gets
|
|
127
|
-
break if line.eql?("\r\n")
|
|
128
|
-
fake_log.info(line.inspect)
|
|
129
|
-
body += line
|
|
130
|
-
end
|
|
131
|
-
socket.print("HTTP/1.1 200 OK\r\n")
|
|
132
|
-
socket.print("Content-Length: 4\r\n")
|
|
133
|
-
socket.print("\r\n")
|
|
134
|
-
socket.print('Done')
|
|
135
|
-
socket.close
|
|
136
|
-
end
|
|
137
|
-
end
|
|
138
|
-
latch.wait
|
|
139
|
-
res = Tempfile.open do |f|
|
|
140
|
-
File.write(f, 'How are you?')
|
|
141
|
-
Zold::Http.new(uri: "http://127.0.0.1:#{port}/").put(f)
|
|
142
|
-
end
|
|
143
|
-
assert_equal(200, res.status, res)
|
|
144
|
-
assert(body.include?('Content-Length: 12'), body)
|
|
145
|
-
assert(body.include?('Content-Type: text/plain'))
|
|
146
|
-
headers = body.split("\n").grep(/^[a-zA-Z-]+:.+$/)
|
|
147
|
-
assert_equal(headers.count, headers.uniq.count)
|
|
148
|
-
thread.kill
|
|
149
|
-
thread.join
|
|
150
|
-
end
|
|
151
|
-
end
|
|
152
|
-
|
|
153
|
-
def test_sends_valid_version_header
|
|
154
|
-
stub_request(:get, 'http://some-host-3/')
|
|
155
|
-
.with(headers: { 'X-Zold-Version' => Zold::VERSION })
|
|
156
|
-
.to_return(status: 200)
|
|
157
|
-
res = Zold::Http.new(uri: 'http://some-host-3/').get
|
|
158
|
-
assert_equal(200, res.status, res)
|
|
159
|
-
end
|
|
160
|
-
|
|
161
|
-
def test_uploads_file
|
|
162
|
-
WebMock.allow_net_connect!
|
|
163
|
-
RandomPort::Pool::SINGLETON.acquire do |port|
|
|
164
|
-
latch = Concurrent::CountDownLatch.new(1)
|
|
165
|
-
thread = Thread.start do
|
|
166
|
-
Zold::VerboseThread.new(fake_log).run do
|
|
167
|
-
server = TCPServer.new(port)
|
|
168
|
-
latch.count_down
|
|
169
|
-
socket = server.accept
|
|
170
|
-
body = ''
|
|
171
|
-
stops = 0
|
|
172
|
-
loop do
|
|
173
|
-
part = socket.read_nonblock(5, exception: false)
|
|
174
|
-
if part == :wait_readable
|
|
175
|
-
break if stops > 5
|
|
176
|
-
stops += 1
|
|
177
|
-
sleep 0.001
|
|
178
|
-
else
|
|
179
|
-
body += part
|
|
180
|
-
stops = 0
|
|
181
|
-
end
|
|
182
|
-
end
|
|
183
|
-
socket.close_read
|
|
184
|
-
socket.print("HTTP/1.1 200 OK\nContent-Length: #{body.length}\n\n#{body}")
|
|
185
|
-
socket.close_write
|
|
186
|
-
end
|
|
187
|
-
end
|
|
188
|
-
latch.wait
|
|
189
|
-
content = "how are you\nmy friend"
|
|
190
|
-
res = Tempfile.open do |f|
|
|
191
|
-
File.write(f, content)
|
|
192
|
-
Zold::Http.new(uri: "http://localhost:#{port}/").put(f)
|
|
193
|
-
end
|
|
194
|
-
assert_equal(200, res.status, res)
|
|
195
|
-
assert(res.body.include?(content), res)
|
|
196
|
-
thread.kill
|
|
197
|
-
thread.join
|
|
198
|
-
end
|
|
199
|
-
end
|
|
200
|
-
|
|
201
|
-
def test_downloads_file
|
|
202
|
-
WebMock.allow_net_connect!
|
|
203
|
-
RandomPort::Pool::SINGLETON.acquire do |port|
|
|
204
|
-
content = "how are you\nmy friend" * 1000
|
|
205
|
-
latch = Concurrent::CountDownLatch.new(1)
|
|
206
|
-
thread = Thread.start do
|
|
207
|
-
Zold::VerboseThread.new(fake_log).run do
|
|
208
|
-
server = TCPServer.new(port)
|
|
209
|
-
latch.count_down
|
|
210
|
-
socket = server.accept
|
|
211
|
-
socket.print("HTTP/1.1 200 OK\nContent-Length: #{content.length}\n\n#{content}")
|
|
212
|
-
socket.close_write
|
|
213
|
-
end
|
|
214
|
-
end
|
|
215
|
-
latch.wait
|
|
216
|
-
body = Tempfile.open do |f|
|
|
217
|
-
Zold::Http.new(uri: "http://localhost:#{port}/").get_file(f)
|
|
218
|
-
File.read(f)
|
|
219
|
-
end
|
|
220
|
-
assert(body.include?(content), body)
|
|
221
|
-
thread.kill
|
|
222
|
-
thread.join
|
|
223
|
-
end
|
|
224
|
-
end
|
|
225
|
-
end
|
data/test/test_hungry_wallets.rb
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# Copyright (c) 2018-2024 Zerocracy
|
|
4
|
-
#
|
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
# of this software and associated documentation files (the 'Software'), to deal
|
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
# furnished to do so, subject to the following conditions:
|
|
11
|
-
#
|
|
12
|
-
# The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
# copies or substantial portions of the Software.
|
|
14
|
-
#
|
|
15
|
-
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
# SOFTWARE.
|
|
22
|
-
|
|
23
|
-
require 'minitest/autorun'
|
|
24
|
-
require 'webmock/minitest'
|
|
25
|
-
require_relative 'test__helper'
|
|
26
|
-
require_relative 'fake_home'
|
|
27
|
-
require_relative '../lib/zold/key'
|
|
28
|
-
require_relative '../lib/zold/thread_pool'
|
|
29
|
-
require_relative '../lib/zold/wallets'
|
|
30
|
-
require_relative '../lib/zold/hungry_wallets'
|
|
31
|
-
|
|
32
|
-
# HungryWallets test.
|
|
33
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
34
|
-
# Copyright:: Copyright (c) 2018-2024 Zerocracy
|
|
35
|
-
# License:: MIT
|
|
36
|
-
class TestHungryWallets < Zold::Test
|
|
37
|
-
def test_pulls_wallet
|
|
38
|
-
FakeHome.new(log: fake_log).run do |home|
|
|
39
|
-
id = Zold::Id.new
|
|
40
|
-
get = stub_request(:get, "http://localhost:4096/wallet/#{id}").to_return(status: 404)
|
|
41
|
-
remotes = home.remotes
|
|
42
|
-
remotes.add('localhost', 4096)
|
|
43
|
-
pool = Zold::ThreadPool.new('test', log: fake_log)
|
|
44
|
-
wallets = Zold::HungryWallets.new(
|
|
45
|
-
home.wallets, remotes, File.join(home.dir, 'copies'),
|
|
46
|
-
pool, log: fake_log
|
|
47
|
-
)
|
|
48
|
-
wallets.acq(id) { |w| assert(!w.exists?) }
|
|
49
|
-
pool.join(2)
|
|
50
|
-
assert_requested(get, times: 1)
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
def test_doesnt_pull_twice_if_not_found
|
|
55
|
-
FakeHome.new(log: fake_log).run do |home|
|
|
56
|
-
id = Zold::Id.new
|
|
57
|
-
get = stub_request(:get, "http://localhost:4096/wallet/#{id}").to_return(status: 404)
|
|
58
|
-
remotes = home.remotes
|
|
59
|
-
remotes.add('localhost', 4096)
|
|
60
|
-
pool = Zold::ThreadPool.new('test', log: fake_log)
|
|
61
|
-
wallets = Zold::HungryWallets.new(
|
|
62
|
-
home.wallets, remotes, File.join(home.dir, 'copies'),
|
|
63
|
-
pool, log: fake_log
|
|
64
|
-
)
|
|
65
|
-
3.times do
|
|
66
|
-
wallets.acq(id) { |w| assert(!w.exists?) }
|
|
67
|
-
sleep 0.2
|
|
68
|
-
end
|
|
69
|
-
pool.join(2)
|
|
70
|
-
assert_requested(get, times: 1)
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
def test_doesnt_pull_wallet_if_exists
|
|
75
|
-
FakeHome.new(log: fake_log).run do |home|
|
|
76
|
-
pool = Zold::ThreadPool.new('test', log: fake_log)
|
|
77
|
-
remotes = home.remotes
|
|
78
|
-
remotes.add('localhost', 4096)
|
|
79
|
-
wallet = home.create_wallet
|
|
80
|
-
get = stub_request(:get, "http://localhost:4096/wallet/#{wallet.id}").to_return(status: 200)
|
|
81
|
-
wallets = Zold::HungryWallets.new(
|
|
82
|
-
home.wallets, remotes, File.join(home.dir, 'copies'),
|
|
83
|
-
pool, log: fake_log
|
|
84
|
-
)
|
|
85
|
-
wallets.acq(wallet.id) { |w| assert(w.exists?) }
|
|
86
|
-
pool.join(2)
|
|
87
|
-
assert_requested(get, times: 0)
|
|
88
|
-
end
|
|
89
|
-
end
|
|
90
|
-
end
|
data/test/test_id.rb
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# Copyright (c) 2018-2024 Zerocracy
|
|
4
|
-
#
|
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
# of this software and associated documentation files (the 'Software'), to deal
|
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
# furnished to do so, subject to the following conditions:
|
|
11
|
-
#
|
|
12
|
-
# The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
# copies or substantial portions of the Software.
|
|
14
|
-
#
|
|
15
|
-
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
# SOFTWARE.
|
|
22
|
-
|
|
23
|
-
require 'minitest/autorun'
|
|
24
|
-
require 'tmpdir'
|
|
25
|
-
require_relative 'test__helper'
|
|
26
|
-
require_relative '../lib/zold/id'
|
|
27
|
-
|
|
28
|
-
# ID test.
|
|
29
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
30
|
-
# Copyright:: Copyright (c) 2018-2024 Zerocracy
|
|
31
|
-
# License:: MIT
|
|
32
|
-
class TestId < Zold::Test
|
|
33
|
-
def test_generates_new_id
|
|
34
|
-
50.times do
|
|
35
|
-
id = Zold::Id.new
|
|
36
|
-
assert id.to_s.length == 16
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def test_generates_different_ids
|
|
41
|
-
before = ''
|
|
42
|
-
500.times do
|
|
43
|
-
id = Zold::Id.new
|
|
44
|
-
assert id.to_s != before.to_s
|
|
45
|
-
before = id
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def test_list_of_banned_ids_is_not_empty
|
|
50
|
-
assert(!Zold::Id::BANNED.empty?)
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def test_checks_for_root
|
|
54
|
-
assert(Zold::Id::ROOT.root?)
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def test_generates_id_only_once
|
|
58
|
-
id = Zold::Id.new
|
|
59
|
-
before = id.to_s
|
|
60
|
-
5.times do
|
|
61
|
-
assert id.to_s == before
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def test_parses_id
|
|
66
|
-
hex = 'ff01889402fe0954'
|
|
67
|
-
id = Zold::Id.new(hex)
|
|
68
|
-
assert(id.to_s == hex, "#{id} is not equal to #{hex}")
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
def test_compares_two_ids_by_text
|
|
72
|
-
id = Zold::Id.new.to_s
|
|
73
|
-
assert_equal(Zold::Id.new(id), Zold::Id.new(id))
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
def test_compares_two_ids
|
|
77
|
-
assert Zold::Id.new(Zold::Id::ROOT.to_s) == Zold::Id.new('0000000000000000')
|
|
78
|
-
end
|
|
79
|
-
end
|
data/test/test_json_page.rb
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# Copyright (c) 2018-2024 Zerocracy
|
|
4
|
-
#
|
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
# of this software and associated documentation files (the 'Software'), to deal
|
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
# furnished to do so, subject to the following conditions:
|
|
11
|
-
#
|
|
12
|
-
# The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
# copies or substantial portions of the Software.
|
|
14
|
-
#
|
|
15
|
-
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
# SOFTWARE.
|
|
22
|
-
|
|
23
|
-
require 'minitest/autorun'
|
|
24
|
-
require_relative 'test__helper'
|
|
25
|
-
require_relative '../lib/zold/json_page'
|
|
26
|
-
|
|
27
|
-
# JsonPage test.
|
|
28
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
29
|
-
# Copyright:: Copyright (c) 2018-2024 Zerocracy
|
|
30
|
-
# License:: MIT
|
|
31
|
-
class TestJsonPage < Zold::Test
|
|
32
|
-
def test_parses_json_page
|
|
33
|
-
assert_equal(1, Zold::JsonPage.new('{"x": 1}').to_hash['x'])
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def test_parses_broken_json_page
|
|
37
|
-
assert_raises Zold::JsonPage::CantParse do
|
|
38
|
-
Zold::JsonPage.new('not json').to_hash
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
def test_parses_empty_page
|
|
43
|
-
assert_raises Zold::JsonPage::CantParse do
|
|
44
|
-
Zold::JsonPage.new('').to_hash
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
end
|
data/test/test_key.rb
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# Copyright (c) 2018-2024 Zerocracy
|
|
4
|
-
#
|
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
# of this software and associated documentation files (the 'Software'), to deal
|
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
# furnished to do so, subject to the following conditions:
|
|
11
|
-
#
|
|
12
|
-
# The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
# copies or substantial portions of the Software.
|
|
14
|
-
#
|
|
15
|
-
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
# SOFTWARE.
|
|
22
|
-
|
|
23
|
-
require 'minitest/autorun'
|
|
24
|
-
require 'tmpdir'
|
|
25
|
-
require 'openssl'
|
|
26
|
-
require_relative 'test__helper'
|
|
27
|
-
require_relative '../lib/zold/key'
|
|
28
|
-
|
|
29
|
-
# Key test.
|
|
30
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
31
|
-
# Copyright:: Copyright (c) 2018-2024 Zerocracy
|
|
32
|
-
# License:: MIT
|
|
33
|
-
class TestKey < Zold::Test
|
|
34
|
-
def test_reads_public_rsa
|
|
35
|
-
key = Zold::Key.new(file: 'fixtures/id_rsa.pub')
|
|
36
|
-
assert(key.to_pub.start_with?('MIICI'))
|
|
37
|
-
assert(key.to_pub.end_with?('EAAQ=='))
|
|
38
|
-
assert(!key.to_pub.include?("\n"))
|
|
39
|
-
assert(Zold::Key.new(text: key.to_pub).to_pub.start_with?('MIICI'))
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
def test_reads_private_rsa
|
|
43
|
-
key = Zold::Key.new(file: 'fixtures/id_rsa')
|
|
44
|
-
assert(key.to_pub.start_with?('MIIJJ'))
|
|
45
|
-
assert(key.to_pub.end_with?('Sg=='))
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
def test_reads_public_root_rsa
|
|
49
|
-
key = Zold::Key::ROOT
|
|
50
|
-
assert(key.to_pub.start_with?('MIICIjANBgkqhkiG9'))
|
|
51
|
-
assert(key.to_pub.end_with?('3Tp1UCAwEAAQ=='))
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
def test_signs_and_verifies
|
|
55
|
-
pub = Zold::Key.new(file: 'fixtures/id_rsa.pub')
|
|
56
|
-
pvt = Zold::Key.new(file: 'fixtures/id_rsa')
|
|
57
|
-
text = 'How are you, my friend?'
|
|
58
|
-
signature = pvt.sign(text)
|
|
59
|
-
assert(pub.verify(signature, text))
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
def test_signs_and_verifies_with_random_key
|
|
63
|
-
Dir.mktmpdir do |dir|
|
|
64
|
-
key = OpenSSL::PKey::RSA.new(2048)
|
|
65
|
-
file = File.join(dir, 'temp')
|
|
66
|
-
File.write(file, key.public_key.to_s)
|
|
67
|
-
pub = Zold::Key.new(file: file)
|
|
68
|
-
File.write(file, key.to_s)
|
|
69
|
-
pvt = Zold::Key.new(file: file)
|
|
70
|
-
text = 'How are you doing, dude?'
|
|
71
|
-
signature = pvt.sign(text)
|
|
72
|
-
assert(pub.verify(signature, text))
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
def test_read_public_keys
|
|
77
|
-
Dir.new('fixtures/keys').grep(/\.pub$/).each do |f|
|
|
78
|
-
path = "fixtures/keys/#{f}"
|
|
79
|
-
pub = Zold::Key.new(file: path)
|
|
80
|
-
assert(pub.to_pub.length > 100)
|
|
81
|
-
end
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
def test_signs_with_real_keys
|
|
85
|
-
Dir.new('fixtures/keys').grep(/[0-9]+$/).each do |f|
|
|
86
|
-
pvt = Zold::Key.new(file: "fixtures/keys/#{f}")
|
|
87
|
-
pub = Zold::Key.new(file: "fixtures/keys/#{f}.pub")
|
|
88
|
-
text = 'How are you doing, my friend?'
|
|
89
|
-
signature = pvt.sign(text)
|
|
90
|
-
assert(pub.verify(signature, text))
|
|
91
|
-
end
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
def test_parses_openssl_generated_keys
|
|
95
|
-
rsa = OpenSSL::PKey::RSA.new(2048)
|
|
96
|
-
Zold::Key.new(text: rsa.to_pem).to_s
|
|
97
|
-
Zold::Key.new(text: rsa.public_key.to_pem).to_s
|
|
98
|
-
end
|
|
99
|
-
end
|
data/test/test_log.rb
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# Copyright (c) 2018-2024 Zerocracy
|
|
4
|
-
#
|
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
# of this software and associated documentation files (the 'Software'), to deal
|
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
# furnished to do so, subject to the following conditions:
|
|
11
|
-
#
|
|
12
|
-
# The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
# copies or substantial portions of the Software.
|
|
14
|
-
#
|
|
15
|
-
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
# SOFTWARE.
|
|
22
|
-
|
|
23
|
-
require 'minitest/autorun'
|
|
24
|
-
require 'threads'
|
|
25
|
-
require_relative 'test__helper'
|
|
26
|
-
require_relative '../lib/zold/log'
|
|
27
|
-
|
|
28
|
-
# Log test.
|
|
29
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
30
|
-
# Copyright:: Copyright (c) 2018-2024 Zerocracy
|
|
31
|
-
# License:: MIT
|
|
32
|
-
class TestLog < Zold::Test
|
|
33
|
-
def test_prints_from_many_threads
|
|
34
|
-
Threads.new(20).assert do
|
|
35
|
-
fake_log.debug("This is debug\nand it is multi\nline")
|
|
36
|
-
fake_log.info('This is info')
|
|
37
|
-
fake_log.error('This is error')
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def test_prints_with_various_formatters
|
|
42
|
-
log = Zold::Log::VERBOSE.dup
|
|
43
|
-
log.formatter = Zold::Log::FULL
|
|
44
|
-
log.debug("This is info\nand it is multi\nline")
|
|
45
|
-
log.debug('Works fine?')
|
|
46
|
-
log.debug(true)
|
|
47
|
-
log.debug(1)
|
|
48
|
-
end
|
|
49
|
-
end
|