rubynas 0.1.0.pre.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.
Files changed (112) hide show
  1. data/.gitignore +23 -0
  2. data/.gitmodules +3 -0
  3. data/.rspec +2 -0
  4. data/.ruby-version +1 -0
  5. data/Gemfile +4 -0
  6. data/Gemfile.lock +196 -0
  7. data/Guardfile +8 -0
  8. data/LICENSE.txt +7 -0
  9. data/Procfile +2 -0
  10. data/README.md +151 -0
  11. data/Rakefile +14 -0
  12. data/Vagrantfile +99 -0
  13. data/bin/rubynas +63 -0
  14. data/config.ru +5 -0
  15. data/doc/README_FOR_APP +2 -0
  16. data/doc/macosx_shares.png +0 -0
  17. data/doc/shares_overview.png +0 -0
  18. data/lib/rubynas.rb +35 -0
  19. data/lib/rubynas/apis/group_api.rb +51 -0
  20. data/lib/rubynas/apis/system_information_api.rb +13 -0
  21. data/lib/rubynas/apis/user_api.rb +85 -0
  22. data/lib/rubynas/apis/volume_api.rb +50 -0
  23. data/lib/rubynas/config.rb +63 -0
  24. data/lib/rubynas/db/migrate/20130302164415_devise_create_users.rb +46 -0
  25. data/lib/rubynas/db/migrate/20130322143040_create_volumes.rb +10 -0
  26. data/lib/rubynas/db/migrate/20130331102556_create_shared_folders.rb +10 -0
  27. data/lib/rubynas/db/migrate/20130331103034_create_shared_folder_services.rb +11 -0
  28. data/lib/rubynas/installers/base_installer.rb +70 -0
  29. data/lib/rubynas/installers/debian_installer.rb +199 -0
  30. data/lib/rubynas/installers/ubuntu_installer.rb +2 -0
  31. data/lib/rubynas/installers/ubuntu_precise_installer.rb +2 -0
  32. data/lib/rubynas/models/.gitkeep +0 -0
  33. data/lib/rubynas/models/ldap_group.rb +21 -0
  34. data/lib/rubynas/models/ldap_org_unit.rb +13 -0
  35. data/lib/rubynas/models/ldap_user.rb +31 -0
  36. data/lib/rubynas/models/shared_folder.rb +32 -0
  37. data/lib/rubynas/models/shared_folder_service.rb +15 -0
  38. data/lib/rubynas/models/volume.rb +16 -0
  39. data/lib/rubynas/services/afp_share_service.rb +9 -0
  40. data/lib/rubynas/services/service.rb +4 -0
  41. data/lib/rubynas/services/share_service.rb +3 -0
  42. data/lib/rubynas/version.rb +3 -0
  43. data/rubynas.gemspec +69 -0
  44. data/rubynas.ini +24 -0
  45. data/sandbox/ldap/base.ldif +50 -0
  46. data/sandbox/ldap/data/.gitkeep +0 -0
  47. data/sandbox/ldap/data/dc=rubynas,dc=com.ldif +14 -0
  48. data/sandbox/ldap/local.schema +6 -0
  49. data/sandbox/ldap/schema/README +80 -0
  50. data/sandbox/ldap/schema/apple.schema +1727 -0
  51. data/sandbox/ldap/schema/apple_auxillary.schema +20 -0
  52. data/sandbox/ldap/schema/collective.ldif +48 -0
  53. data/sandbox/ldap/schema/collective.schema +190 -0
  54. data/sandbox/ldap/schema/corba.ldif +42 -0
  55. data/sandbox/ldap/schema/corba.schema +239 -0
  56. data/sandbox/ldap/schema/core.ldif +591 -0
  57. data/sandbox/ldap/schema/core.schema +610 -0
  58. data/sandbox/ldap/schema/cosine.ldif +200 -0
  59. data/sandbox/ldap/schema/cosine.schema +2571 -0
  60. data/sandbox/ldap/schema/duaconf.ldif +83 -0
  61. data/sandbox/ldap/schema/duaconf.schema +261 -0
  62. data/sandbox/ldap/schema/dyngroup.ldif +71 -0
  63. data/sandbox/ldap/schema/dyngroup.schema +91 -0
  64. data/sandbox/ldap/schema/fmserver.schema +60 -0
  65. data/sandbox/ldap/schema/inetorgperson.ldif +69 -0
  66. data/sandbox/ldap/schema/inetorgperson.schema +155 -0
  67. data/sandbox/ldap/schema/java.ldif +59 -0
  68. data/sandbox/ldap/schema/java.schema +403 -0
  69. data/sandbox/ldap/schema/krb5-kdc.schema +134 -0
  70. data/sandbox/ldap/schema/microsoft.ext.schema +5383 -0
  71. data/sandbox/ldap/schema/microsoft.schema +4835 -0
  72. data/sandbox/ldap/schema/microsoft.std.schema +480 -0
  73. data/sandbox/ldap/schema/misc.ldif +45 -0
  74. data/sandbox/ldap/schema/misc.schema +75 -0
  75. data/sandbox/ldap/schema/netinfo.schema +240 -0
  76. data/sandbox/ldap/schema/nis.ldif +120 -0
  77. data/sandbox/ldap/schema/nis.schema +241 -0
  78. data/sandbox/ldap/schema/openldap.ldif +88 -0
  79. data/sandbox/ldap/schema/openldap.schema +54 -0
  80. data/sandbox/ldap/schema/pmi.ldif +123 -0
  81. data/sandbox/ldap/schema/pmi.schema +464 -0
  82. data/sandbox/ldap/schema/ppolicy.ldif +75 -0
  83. data/sandbox/ldap/schema/ppolicy.schema +531 -0
  84. data/sandbox/ldap/schema/samba.schema +179 -0
  85. data/sandbox/ldap/slapd.conf +99 -0
  86. data/spec/apis/group_api_spec.rb +97 -0
  87. data/spec/apis/system_information_api_spec.rb +27 -0
  88. data/spec/apis/user_api_spec.rb +113 -0
  89. data/spec/apis/volume_api_spec.rb +98 -0
  90. data/spec/factories/ldap_group.rb +16 -0
  91. data/spec/factories/ldap_users.rb +24 -0
  92. data/spec/factories/shared_folder_services.rb +9 -0
  93. data/spec/factories/shared_folders.rb +15 -0
  94. data/spec/factories/users.rb +8 -0
  95. data/spec/factories/volumes.rb +10 -0
  96. data/spec/installer/base_installer_spec.rb +35 -0
  97. data/spec/installer/debian_installer_spec.rb +86 -0
  98. data/spec/models/ldap_group_spec.rb +21 -0
  99. data/spec/models/ldap_org_unit_spec.rb +19 -0
  100. data/spec/models/ldap_user_spec.rb +19 -0
  101. data/spec/models/shared_folder_service_spec.rb +25 -0
  102. data/spec/models/shared_folder_spec.rb +27 -0
  103. data/spec/models/volume_spec.rb +5 -0
  104. data/spec/services/afp_share_service_spec.rb +5 -0
  105. data/spec/services/service_spec.rb +5 -0
  106. data/spec/services/share_service_spec.rb +5 -0
  107. data/spec/spec_helper.rb +30 -0
  108. data/spec/support/db_cleaner.rb +16 -0
  109. data/spec/support/factory_girl.rb +7 -0
  110. data/spec/support/logger.rb +1 -0
  111. data/spec/support/rack-test.rb +6 -0
  112. metadata +633 -0
@@ -0,0 +1,98 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Restful Volume API' do
4
+ include Rack::Test::Methods
5
+
6
+ def app
7
+ VolumeApi
8
+ end
9
+
10
+ context "GET /" do
11
+ before do
12
+ create :root_volume
13
+ get '/'
14
+ end
15
+ subject { last_response }
16
+
17
+ it { should be_ok }
18
+ its(:body) { should include('/') }
19
+ its(:body) { should include('System Volume') }
20
+ end
21
+
22
+ context "GET /:id" do
23
+ context "with volume" do
24
+ before do
25
+ create :root_volume
26
+ get '/1'
27
+ end
28
+ subject { last_response }
29
+
30
+ it { should be_ok }
31
+ its(:body) { should include('/') }
32
+ its(:body) { should include('System Volume') }
33
+ end
34
+
35
+ context "without volume" do
36
+ before do
37
+ get '/123123'
38
+ end
39
+ subject { last_response }
40
+
41
+ its(:status) { should == 404 }
42
+ end
43
+ end
44
+
45
+ context "PUT /:id" do
46
+ context "with volume" do
47
+ before do
48
+ create :root_volume
49
+ put '/1', name: "Foo"
50
+ end
51
+ subject { last_response }
52
+
53
+ it { should be_ok }
54
+ specify { Volume.find(1).name.should == "Foo" }
55
+ end
56
+
57
+ context "without volume" do
58
+ before do
59
+ put '/123123', name: "Foo"
60
+ end
61
+ subject { last_response }
62
+
63
+ its(:status) { should == 404 }
64
+ end
65
+ end
66
+
67
+ context "POST /:id" do
68
+ before do
69
+ post '/', name: "Foo", path: "/"
70
+ end
71
+ subject { last_response }
72
+
73
+ its(:status) { should == 201 }
74
+ specify { Volume.where(name: "Foo").should have(1).item }
75
+ end
76
+
77
+ context "DELETE /:id" do
78
+ context "with volume" do
79
+ before do
80
+ create :root_volume
81
+ delete '/1'
82
+ end
83
+ subject { last_response }
84
+
85
+ it { should be_ok }
86
+ specify { Volume.all.should be_empty }
87
+ end
88
+
89
+ context "without volume" do
90
+ before do
91
+ delete '/123123'
92
+ end
93
+ subject { last_response }
94
+
95
+ its(:status) { should == 404 }
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,16 @@
1
+ require 'factory_girl'
2
+
3
+ FactoryGirl.define do
4
+ factory :ldap_group do
5
+ end
6
+
7
+ factory :user_ldap_group, :parent => :ldap_group do
8
+ common_name "Users"
9
+ gid_number 1000
10
+ end
11
+
12
+ factory :admin_ldap_group, :parent => :ldap_group do
13
+ common_name "Administrators"
14
+ gid_number 0
15
+ end
16
+ end
@@ -0,0 +1,24 @@
1
+ require 'factory_girl'
2
+
3
+ FactoryGirl.define do
4
+ factory :ldap_user do
5
+ common_name "User"
6
+ mail "user@rubynas.com"
7
+ home_directory "/home/user"
8
+ uid "user"
9
+ surname "User"
10
+ uid_number 1000
11
+ gid_number 1000
12
+ userPassword { ActiveLdap::UserPassword.sha 'secret' }
13
+ end
14
+
15
+ factory :admin_ldap_user, :parent => :ldap_user do
16
+ common_name "Admin"
17
+ mail "admin@rubynas.com"
18
+ home_directory "/root"
19
+ uid "example_admin"
20
+ surname "Admin"
21
+ uid_number 0
22
+ gid_number 0
23
+ end
24
+ end
@@ -0,0 +1,9 @@
1
+ require 'factory_girl'
2
+
3
+ FactoryGirl.define do
4
+ factory :shared_folder_service do
5
+ service_class 'AfpShareService'
6
+ options({ time_machine: true })
7
+ shared_folder
8
+ end
9
+ end
@@ -0,0 +1,15 @@
1
+ require 'factory_girl'
2
+
3
+ FactoryGirl.define do
4
+ factory :shared_folder do
5
+ name "System"
6
+ path "/"
7
+ end
8
+
9
+ factory :shared_folder_with_services, parent: :shared_folder do
10
+ after(:create) do |shared_folder, evaluator|
11
+ shared_folder << build(:shared_folder_service)
12
+ shared_folder.save
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,8 @@
1
+ require 'factory_girl'
2
+
3
+ FactoryGirl.define do
4
+ factory :user do
5
+ email 'test@rubynas.com'
6
+ password 'secret123'
7
+ end
8
+ end
@@ -0,0 +1,10 @@
1
+ require 'factory_girl'
2
+
3
+ FactoryGirl.define do
4
+ factory :volume
5
+
6
+ factory :root_volume, parent: :volume do
7
+ name "System Volume"
8
+ path "/"
9
+ end
10
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe BaseInstaller do
4
+ subject { described_class.new('rubynas.com', 'admin', 'secret') }
5
+
6
+ its(:domain) { should == 'rubynas.com' }
7
+ its(:admin) { should == 'admin' }
8
+ its(:password) { should == 'secret' }
9
+
10
+ its(:domain_parts) { should == ['rubynas', 'com'] }
11
+ its(:ldap_base) { should == 'dc=rubynas,dc=com' }
12
+ its(:admin_ldap_dn) { should == 'cn=admin,dc=rubynas,dc=com' }
13
+
14
+ context 'non root' do
15
+ its(:sudo) { should == 'sudo' }
16
+ its(:root?) { should be_false }
17
+
18
+ specify do
19
+ subject.should_receive(:system).with("sudo date")
20
+ subject.sudo_system('date')
21
+ end
22
+ end
23
+
24
+ context 'root' do
25
+ before { Process.stub(:uid) { 0 } }
26
+
27
+ its(:sudo) { should be_nil }
28
+ its(:root?) { should be_true }
29
+
30
+ specify do
31
+ subject.should_receive(:system).with("date")
32
+ subject.sudo_system('date')
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,86 @@
1
+ require 'spec_helper'
2
+
3
+ shared_examples 'aptget-install' do |method|
4
+ it 'should work' do
5
+ subject.should_receive(:system).and_return(true)
6
+ subject.send(method)
7
+ end
8
+
9
+ it 'can fail' do
10
+ subject.should_receive(:system).and_return(false)
11
+ expect { subject.send(method) }.to(
12
+ raise_error(BaseInstaller::InstallError))
13
+ end
14
+ end
15
+
16
+ shared_examples 'aptget-configure' do |method|
17
+ it 'should work' do
18
+ IO.stub(:popen)
19
+ subject.send(method)
20
+ end
21
+
22
+ it 'can fail' do
23
+ IO.stub(:popen)
24
+ $?.stub(:exited?) { false }
25
+ expect { subject.send(method) }.to(
26
+ raise_error(BaseInstaller::ConfigurationError))
27
+ end
28
+ end
29
+
30
+ describe DebianInstaller do
31
+ subject { described_class.new('rubynas.com', 'admin', 'secret') }
32
+
33
+ context '#prepare_install' do
34
+ it_behaves_like 'aptget-install', :prepare_install
35
+ end
36
+
37
+ context '#install' do
38
+ it 'should work' do
39
+ subject.should_receive(:system).and_return(true)
40
+ subject.install
41
+ end
42
+
43
+ it 'can fail' do
44
+ subject.should_receive(:system).and_return(false)
45
+ expect { subject.install }.to(
46
+ raise_error(BaseInstaller::PackageError))
47
+ end
48
+ end
49
+
50
+ context '#debconf' do
51
+ it 'should work' do
52
+ IO.stub(:popen)
53
+ subject.debconf('ldap', 'password', :password, 'secret')
54
+ end
55
+
56
+ it 'can fail' do
57
+ IO.stub(:popen)
58
+ $?.stub(:exited?) { false }
59
+ expect { subject.debconf('ldap', 'password', :password, 'secret') }.to(
60
+ raise_error(BaseInstaller::ConfigurationError))
61
+ end
62
+ end
63
+
64
+ context '#configure_ldap' do
65
+ it_behaves_like 'aptget-configure', :configure_ldap
66
+ end
67
+
68
+ context '#install_ldap' do
69
+ it_behaves_like 'aptget-install', :install_ldap
70
+ end
71
+
72
+ context '#configure_pam_auth' do
73
+ it_behaves_like 'aptget-configure', :configure_pam_auth
74
+ end
75
+
76
+ context '#install_pam_auth' do
77
+ it_behaves_like 'aptget-install', :install_pam_auth
78
+ end
79
+
80
+ pending '#configure_app' do
81
+ end
82
+
83
+ context '#install_app' do
84
+ it_behaves_like 'aptget-install', :install_app
85
+ end
86
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe LdapGroup do
4
+ context "#find_or_create_administrators" do
5
+ before do
6
+ if group = (LdapGroup.find(:cn => 'Administrators') rescue nil)
7
+ group.destroy
8
+ end
9
+ end
10
+
11
+ it "creates an admin" do
12
+ LdapGroup.find_or_create_administrators.common_name.should == \
13
+ "Administrators"
14
+ end
15
+
16
+ it "creates & finds an admin" do
17
+ LdapGroup.find_or_create_administrators.should == \
18
+ LdapGroup.find_or_create_administrators
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe LdapOrgUnit do
4
+ context "#find_or_create" do
5
+ before do
6
+ if group = (LdapOrgUnit.find('testers') rescue nil)
7
+ group.destroy
8
+ end
9
+ end
10
+
11
+ it "creates the unit" do
12
+ LdapOrgUnit.find_or_create('testers').ou.should == "testers"
13
+ end
14
+
15
+ it "craetes and finds the unit" do
16
+ LdapOrgUnit.find_or_create('testers') == LdapOrgUnit.find_or_create('testers')
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe LdapUser do
4
+ context "#find_or_create_admin" do
5
+ before do
6
+ if user = (LdapUser.find(:cn => 'Admin') rescue nil)
7
+ user.destroy
8
+ end
9
+ end
10
+
11
+ it "creates an admin" do
12
+ LdapUser.find_or_create_admin.common_name.should == "Admin"
13
+ end
14
+
15
+ it "creates & finds an admin" do
16
+ LdapUser.find_or_create_admin.should == LdapUser.find_or_create_admin
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe SharedFolderService do
4
+ context "new shared folder service" do
5
+ its(:valid?) { should be_false }
6
+ end
7
+
8
+ context "#service_class" do
9
+ it "stores a service class" do
10
+ subject.service_class = String
11
+ subject.service_class.should == String
12
+ end
13
+ end
14
+
15
+ context "with valid shared folder service" do
16
+ subject { create(:shared_folder_service) }
17
+
18
+ context "after loading" do
19
+ before { subject.reload }
20
+
21
+ pending(:service_class) { should == AfpShareService }
22
+ pending(:options) { should include(time_machine: true) }
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe SharedFolder do
4
+ context "empty object" do
5
+ its(:valid?) { should be_false }
6
+ end
7
+
8
+ context "filled object" do
9
+ subject { build :shared_folder }
10
+
11
+ its(:valid?) { should be_true }
12
+ end
13
+
14
+ context "invalid path" do
15
+ context "don't exist" do
16
+ subject { build :shared_folder, path: "/aksjhdkjahsd" }
17
+
18
+ its(:valid?) { should be_false }
19
+ end
20
+
21
+ context "no directory" do
22
+ subject { build :shared_folder, path: "spec/spec_helper.rb" }
23
+
24
+ its(:valid?) { should be_false }
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe Volume do
4
+ pending "add some examples to (or delete) #{__FILE__}"
5
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe AfpShareService do
4
+
5
+ end