kanrisuru 0.14.0 → 0.16.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +27 -0
  3. data/README.md +5 -5
  4. data/kanrisuru.gemspec +7 -3
  5. data/lib/kanrisuru/command.rb +16 -3
  6. data/lib/kanrisuru/core/apt/parsers/base.rb +1 -1
  7. data/lib/kanrisuru/core/disk/commands/lsblk.rb +6 -11
  8. data/lib/kanrisuru/core/disk/constants.rb +9 -0
  9. data/lib/kanrisuru/core/disk/parser.rb +1 -0
  10. data/lib/kanrisuru/core/disk/parsers/lsblk_version.rb +21 -0
  11. data/lib/kanrisuru/core/disk.rb +1 -0
  12. data/lib/kanrisuru/core/dmi/commands/dmi.rb +1 -1
  13. data/lib/kanrisuru/core/file/commands/chmod.rb +1 -1
  14. data/lib/kanrisuru/core/file/commands/copy.rb +1 -3
  15. data/lib/kanrisuru/core/file/commands/mkdir.rb +11 -6
  16. data/lib/kanrisuru/core/file/commands/rm.rb +4 -1
  17. data/lib/kanrisuru/core/file/commands/touch.rb +2 -1
  18. data/lib/kanrisuru/core/ip/commands/address.rb +64 -47
  19. data/lib/kanrisuru/core/ip/commands/address_label.rb +32 -16
  20. data/lib/kanrisuru/core/ip/commands/link.rb +96 -54
  21. data/lib/kanrisuru/core/ip/commands/link_set_opts.rb +61 -0
  22. data/lib/kanrisuru/core/ip/commands/link_type_opts.rb +313 -0
  23. data/lib/kanrisuru/core/ip/commands/maddress.rb +22 -13
  24. data/lib/kanrisuru/core/ip/commands/neighbour.rb +49 -32
  25. data/lib/kanrisuru/core/ip/commands/route.rb +130 -93
  26. data/lib/kanrisuru/core/ip/commands/rule.rb +37 -22
  27. data/lib/kanrisuru/core/ip/commands.rb +5 -3
  28. data/lib/kanrisuru/core/ip/constants.rb +12 -0
  29. data/lib/kanrisuru/core/ip/parser.rb +1 -0
  30. data/lib/kanrisuru/core/ip/parsers/version.rb +15 -0
  31. data/lib/kanrisuru/core/ip.rb +10 -7
  32. data/lib/kanrisuru/core/system/commands/kill.rb +1 -1
  33. data/lib/kanrisuru/core/user/commands/create_user.rb +9 -17
  34. data/lib/kanrisuru/core/user/commands/delete_user.rb +1 -1
  35. data/lib/kanrisuru/core/user/commands/update_user.rb +14 -23
  36. data/lib/kanrisuru/core/zypper/commands/add_repo.rb +1 -8
  37. data/lib/kanrisuru/core/zypper/commands/add_service.rb +4 -2
  38. data/lib/kanrisuru/core/zypper/commands/info.rb +1 -2
  39. data/lib/kanrisuru/core/zypper/commands/install.rb +2 -3
  40. data/lib/kanrisuru/core/zypper/commands/modify_repo.rb +1 -7
  41. data/lib/kanrisuru/core/zypper/commands/modify_service.rb +3 -1
  42. data/lib/kanrisuru/core/zypper/commands/remove.rb +1 -2
  43. data/lib/kanrisuru/core/zypper/commands/remove_repo.rb +3 -3
  44. data/lib/kanrisuru/core/zypper/commands/remove_service.rb +6 -1
  45. data/lib/kanrisuru/core/zypper/commands/search.rb +1 -3
  46. data/lib/kanrisuru/core/zypper/commands/source_install.rb +2 -0
  47. data/lib/kanrisuru/core/zypper/commands.rb +10 -1
  48. data/lib/kanrisuru/os_package.rb +2 -0
  49. data/lib/kanrisuru/remote/host.rb +1 -3
  50. data/lib/kanrisuru/result.rb +15 -0
  51. data/lib/kanrisuru/version.rb +1 -1
  52. data/spec/functional/core/archive_spec.rb +1 -1
  53. data/spec/functional/core/disk_spec.rb +77 -0
  54. data/spec/functional/core/dmi_spec.rb +78 -0
  55. data/spec/functional/core/file_spec.rb +284 -0
  56. data/spec/functional/core/group_spec.rb +62 -0
  57. data/spec/functional/core/ip_address_label_spec.rb +81 -0
  58. data/spec/functional/core/ip_address_spec.rb +95 -0
  59. data/spec/functional/core/ip_link_spec.rb +814 -0
  60. data/spec/functional/core/ip_maddress_spec.rb +78 -0
  61. data/spec/functional/core/ip_neighbour_spec.rb +119 -0
  62. data/spec/functional/core/ip_route_spec.rb +174 -0
  63. data/spec/functional/core/ip_rule_spec.rb +75 -0
  64. data/spec/functional/core/ip_spec.rb +27 -0
  65. data/spec/functional/core/system_spec.rb +135 -0
  66. data/spec/functional/core/user_spec.rb +97 -0
  67. data/spec/functional/core/zypper_spec.rb +708 -0
  68. data/spec/functional/result_spec.rb +91 -44
  69. data/spec/helper/stub_network.rb +7 -3
  70. data/spec/support/shared_examples/integration/core/transfer.rb +1 -1
  71. data/spec/unit/command_spec.rb +2 -0
  72. data/spec/unit/core/ip_spec.rb +12 -0
  73. metadata +25 -4
@@ -0,0 +1,97 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe Kanrisuru::Core::User do
6
+ before(:all) do
7
+ StubNetwork.stub!
8
+ end
9
+
10
+ after(:all) do
11
+ StubNetwork.unstub!
12
+ end
13
+
14
+ let(:host) do
15
+ Kanrisuru::Remote::Host.new(
16
+ host: 'localhost',
17
+ username: 'ubuntu',
18
+ keys: ['id_rsa']
19
+ )
20
+ end
21
+
22
+ it 'prepares create_user command' do
23
+ expect_command(host.create_user('bob'), 'useradd bob -s /bin/false')
24
+ expect_command(host.create_user('bob', uid: 5555), 'useradd bob -u 5555 -s /bin/false')
25
+ expect_command(host.create_user('bob', uid: 5555, non_unique: true), 'useradd bob -u 5555 -o -s /bin/false')
26
+ expect_command(host.create_user('bob', system: true), 'useradd bob -r -s /bin/false')
27
+ expect_command(host.create_user('bob', shell: '/bin/bash'), 'useradd bob -s /bin/bash')
28
+ expect_command(host.create_user('bob', home: '/home/bob1'), 'useradd bob -s /bin/false -d /home/bob1')
29
+ expect_command(host.create_user('bob', home: '/home/bob1', createhome: true),
30
+ 'useradd bob -s /bin/false -d /home/bob1 -m')
31
+ expect_command(host.create_user('bob', home: '/home/bob1', createhome: true, skeleton: '/home/bob1skele'),
32
+ 'useradd bob -s /bin/false -d /home/bob1 -m -k /home/bob1skele')
33
+ expect_command(host.create_user('bob', createhome: false), 'useradd bob -s /bin/false -M')
34
+ expect_command(host.create_user('bob', password: '12345678'), 'useradd bob -s /bin/false -p 12345678')
35
+ expect_command(host.create_user('bob', expires: '2021-12-31'), 'useradd bob -s /bin/false -e 2021-12-31')
36
+
37
+ expect_command(host.create_user('bob', groups: %w[www-data sudo admin]),
38
+ 'useradd bob -s /bin/false -G www-data,sudo,admin')
39
+
40
+ StubNetwork.stub_command!(:group?, { return_value: true })
41
+ expect_command(host.create_user('bob', group: 'www-data'), 'useradd bob -s /bin/false -g www-data')
42
+ expect_command(host.create_user('bob'), 'useradd bob -s /bin/false -N')
43
+ StubNetwork.unstub_command!(:group?)
44
+ end
45
+
46
+ it 'prepares delete_user command' do
47
+ StubNetwork.stub_command!(:get_uid) { 1000 }
48
+ expect_command(host.delete_user('ubuntu'), 'userdel ubuntu')
49
+ expect_command(host.delete_user('ubuntu', force: true), 'userdel ubuntu -f')
50
+ StubNetwork.unstub_command!(:get_uid)
51
+
52
+ StubNetwork.stub_command!(:get_uid, { status: 1 })
53
+ expect(host.delete_user('ubuntu')).to be_falsey
54
+ StubNetwork.unstub_command!(:get_uid)
55
+ end
56
+
57
+ it 'prepares get_uid command' do
58
+ expect_command(host.get_uid('ubuntu'), 'id -u ubuntu')
59
+ end
60
+
61
+ it 'prepares get_user command' do
62
+ expect_command(host.get_user('ubuntu'), 'id ubuntu')
63
+ end
64
+
65
+ it 'prepares user? command' do
66
+ StubNetwork.stub_command!(:get_uid) { 1000 }
67
+ expect(host).to be_user('ubuntu')
68
+ StubNetwork.unstub_command!(:get_uid)
69
+
70
+ StubNetwork.stub_command!(:get_uid, { status: 1 })
71
+ expect(host).not_to be_group('ubuntu')
72
+ StubNetwork.unstub_command!(:get_uid)
73
+ end
74
+
75
+ it 'prepares update_user command' do
76
+ expect_command(host.update_user('bob', home: '/home/bob'), 'usermod bob -d /home/bob')
77
+ expect_command(host.update_user('bob', home: '/home/bob', move_home: true), 'usermod bob -d /home/bob -m')
78
+ expect_command(host.update_user('bob', home: '/home/bob', move_home: true), 'usermod bob -d /home/bob -m')
79
+ expect_command(host.update_user('bob', shell: '/bin/zsh'), 'usermod bob -s /bin/zsh')
80
+ expect_command(host.update_user('bob', uid: 6431), 'usermod bob -u 6431')
81
+ expect_command(host.update_user('bob', uid: 1000, non_unique: true), 'usermod bob -u 1000 -o')
82
+
83
+ StubNetwork.stub_command!(:group?, { return_value: true })
84
+ expect_command(host.update_user('bob', group: 'backup'), 'usermod bob -g backup')
85
+ StubNetwork.unstub_command!(:group?)
86
+
87
+ expect_command(host.update_user('bob', groups: 'backup'), 'usermod bob -G backup')
88
+ expect_command(host.update_user('bob', groups: %w[backup mail]), 'usermod bob -G backup,mail')
89
+ expect_command(host.update_user('bob', groups: %w[backup mail], append: true), 'usermod bob -G backup,mail -a')
90
+
91
+ expect_command(host.update_user('bob', locked: true), 'usermod bob -L -e 1')
92
+ expect_command(host.update_user('bob', locked: false), 'usermod bob -U -e 99999')
93
+ expect_command(host.update_user('bob', locked: false, password: '123456'), 'usermod bob -U -e 99999')
94
+ expect_command(host.update_user('bob', password: '123456'), 'usermod bob -p 123456')
95
+ expect_command(host.update_user('bob', expires: '2022-01-01'), 'usermod bob -e 2022-01-01')
96
+ end
97
+ end