gritano 0.5.3 → 0.5.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,121 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ module Gritano
4
+ module Console
5
+ describe Gritano do
6
+ def create_gritano(home, repo_dir)
7
+ stdin = double()
8
+ stdin.stub(:read).and_return("Your SSHKEY here...")
9
+ Gritano.new(stdin, home, repo_dir)
10
+ end
11
+
12
+ def test_console_call(console, msg)
13
+ executor = double()
14
+ executor.should_receive(:execute).with(msg)
15
+ console.should_receive(:new).and_return(executor)
16
+ create_gritano('.', 'tmp').execute(msg)
17
+ end
18
+
19
+ def test_executor(msg)
20
+ test_console_call(Executor, msg)
21
+ end
22
+
23
+ def test_installer(msg)
24
+ test_console_call(Installer, msg)
25
+ end
26
+
27
+ it "should show the complete help" do
28
+ create_gritano(".", "tmp").
29
+ execute(["help"])[1].
30
+ should == File.open("features/data/local_help.txt").readlines.join.
31
+ gsub('{{VERSION}}', File.open("VERSION").readlines.join)
32
+ end
33
+
34
+ it "should show the version" do
35
+ create_gritano(".", "tmp").
36
+ execute(["version"])[1].
37
+ should == "v#{File.open("VERSION").readlines.join}"
38
+ end
39
+
40
+ it "should list users" do
41
+ test_executor(["user:list"])
42
+ end
43
+
44
+ it "should list users' keys" do
45
+ test_executor(["user:key:list", "login"])
46
+ end
47
+
48
+ it "should list users' repos" do
49
+ test_executor(["user:repo:list", "login"])
50
+ end
51
+
52
+ it "should add users" do
53
+ test_executor(["user:add", "login"])
54
+ end
55
+
56
+ it "should remove users" do
57
+ test_executor(["user:rm", "login"])
58
+ end
59
+
60
+ it "should add users' keys" do
61
+ test_executor(["user:key:add", "login", "keyname"])
62
+ end
63
+
64
+ it "should remove users' keys" do
65
+ test_executor(["user:key:rm", "login", "keyname"])
66
+ end
67
+
68
+ it "should add admin rights to user" do
69
+ test_executor(["user:admin:add", "login"])
70
+ end
71
+
72
+ it "should remove admin rights from users" do
73
+ test_executor(["user:admin:rm", "login"])
74
+ end
75
+
76
+ it "should list repos" do
77
+ test_executor(["repo:list"])
78
+ end
79
+
80
+ it "should create repos" do
81
+ test_executor(["repo:add", "repo.git"])
82
+ end
83
+
84
+ it "should create repos and add a user" do
85
+ test_executor(["repo:add", "repo.git", "login"])
86
+ end
87
+
88
+ it "should list repos' users" do
89
+ test_executor(["repo:user:list", "repo.git"])
90
+ end
91
+
92
+ it "should remove repos" do
93
+ test_executor(["repo:rm", "repo.git"])
94
+ end
95
+
96
+ it "should allow user to read a repo" do
97
+ test_executor(["repo:read:add", "repo.git", "login"])
98
+ end
99
+
100
+ it "should allow user to write to a repo" do
101
+ test_executor(["repo:write:add", "repo.git", "login"])
102
+ end
103
+
104
+ it "should deny user to read a repo" do
105
+ test_executor(["repo:read:rm", "repo.git", "login"])
106
+ end
107
+
108
+ it "should deny user to write to a repo"do
109
+ test_executor(["repo:write:rm", "repo.git", "login"])
110
+ end
111
+
112
+ it "should prepare the environment" do
113
+ test_installer(["setup:prepare"])
114
+ end
115
+
116
+ it "should install" do
117
+ test_installer(["setup:install"])
118
+ end
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,28 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ module Gritano
4
+ module Console
5
+ describe Installer do
6
+ def create_installer(home)
7
+ FileUtils.rm_rf(File.join(home, ".gritano"))
8
+ stdin = double()
9
+ stdin.stub(:read).and_return("Your SSHKEY here...")
10
+ Installer.new(stdin, home)
11
+ end
12
+
13
+ it "should prepare the environment" do
14
+ installer = create_installer("tmp")
15
+ installer.should_receive(:create_gritano_dirs)
16
+ installer.should_receive(:create_sqlite_config)
17
+ installer.execute(["setup:prepare"])
18
+ end
19
+
20
+ it "should install" do
21
+ installer = create_installer("tmp")
22
+ installer.should_receive(:create_database)
23
+ installer.should_receive(:create_authorization_keys)
24
+ installer.execute(["setup:install"])
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,70 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ module Gritano
4
+ module Console
5
+ describe Remote do
6
+ def create_remote(home, repo_dir)
7
+ stdin = double()
8
+ stdin.stub(:read).and_return("Your SSHKEY here...")
9
+ Remote.new(stdin, home, repo_dir)
10
+ end
11
+
12
+ def test_remote_execute(cmd)
13
+ _cmd = ["user:" + cmd[0]] + ["login"] + cmd[1..-1]
14
+ Executor.any_instance.should_receive(:execute).with(_cmd)
15
+ create_remote(".", "tmp").execute(cmd + ["login"])
16
+ end
17
+
18
+ it "should show a help message" do
19
+ create_remote(".", "tmp").
20
+ execute(["help"])[1].
21
+ should == File.open("features/data/remote_help.txt").readlines.join.
22
+ gsub('{{VERSION}}', File.open("VERSION").readlines.join)
23
+ end
24
+
25
+ it "should show the version" do
26
+ create_remote(".", "tmp").
27
+ execute(["version"])[1].
28
+ should == "v#{File.open("VERSION").readlines.join}"
29
+ end
30
+
31
+ it "should list user's repositories" do
32
+ test_remote_execute(["repo:list"])
33
+ end
34
+
35
+ it "should list user's keys" do
36
+ test_remote_execute(["key:list"])
37
+ end
38
+
39
+ it "should add a key" do
40
+ test_remote_execute(["key:add", "keyname"])
41
+ end
42
+
43
+ it "should remove a key" do
44
+ test_remote_execute(["key:rm", "keyname"])
45
+ end
46
+
47
+ it "should execute admin commands" do
48
+ admin = double()
49
+ admin.should_receive(:admin?).and_return(true)
50
+ ::Gritano::User.should_receive(:find_by_login).and_return(admin)
51
+ remote = create_remote(".", "tmp")
52
+ remote.should_receive(:admin_command)
53
+ remote.execute(["admin:user:list"])
54
+ end
55
+
56
+ it "should get a git repository" do
57
+ remote = create_remote(".", "tmp")
58
+ remote.should_receive(:git_receive_pack)
59
+ remote.execute(["git-receive-pack"])
60
+ end
61
+
62
+ it "should send a git repository" do
63
+ remote = create_remote(".", "tmp")
64
+ remote.should_receive(:git_upload_pack)
65
+ remote.execute(["git-upload-pack"])
66
+ end
67
+
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,23 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ module Gritano
4
+ describe Console do
5
+ it "should setup a local console" do
6
+ Console::Base.should_receive(:bin_name=).with("gritano ")
7
+ Console::Remote.should_receive(:bin_name=).with("gritano ")
8
+ Console::Executor.should_receive(:bin_name=).with("gritano ")
9
+ Console::Gritano.should_receive(:bin_name=).with("gritano ")
10
+ Console::Installer.should_receive(:bin_name=).with("gritano ")
11
+ Console.remote_console(false)
12
+ end
13
+
14
+ it "should setup a remote console" do
15
+ Console::Base.should_receive(:bin_name=).with("ssh git@host.com admin:")
16
+ Console::Remote.should_receive(:bin_name=).with("ssh git@host.com ")
17
+ Console::Executor.should_receive(:bin_name=).with("ssh git@host.com admin:")
18
+ Console::Gritano.should_receive(:bin_name=).with("ssh git@host.com admin:")
19
+ Console::Installer.should_receive(:bin_name=).with("ssh git@host.com admin:")
20
+ Console.remote_console(true)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,7 @@
1
+ gritano [command]
2
+
3
+ Examples:
4
+ gritano command:name parameters
5
+
6
+ --
7
+ v{{VERSION}}
@@ -1,18 +1,38 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
- describe Gritano::Key do
4
- it 'should have a name' do
5
- key = Gritano::Key.new(key: "key")
6
- key.should be_invalid
3
+ module Gritano
4
+ describe Key do
5
+
6
+ def create_new_user_and_key
7
+ user = User.create(login: "igor")
8
+ key = user.keys.create(name: "mykey", key: "sshkey")
9
+ return user, key
10
+ end
11
+
12
+ it "should have a name" do
13
+ key = Gritano::Key.new(key: "key")
14
+ key.should be_invalid
15
+ end
16
+
17
+ it "should have a ssh key" do
18
+ key = Gritano::Key.new(name: "name")
19
+ key.should be_invalid
20
+ end
21
+
22
+ it "should have a unique name per user" do
23
+ user, key = create_new_user_and_key
24
+ user.keys.create(name: "mykey", key: "sshkey").should be_invalid
25
+ user.keys.count.should == 1
26
+ end
27
+
28
+ it "should belongs to a user" do
29
+ user, key = create_new_user_and_key
30
+ key.user.should == user
31
+ end
32
+
33
+ it "should generate the authorized_keys files" do
34
+ create_new_user_and_key
35
+ Key.authorized_keys.should == "command=\"gritano-remote igor\" sshkey\n"
36
+ end
7
37
  end
8
-
9
- it 'should have a key' do
10
- key = Gritano::Key.new(name: "name")
11
- key.should be_invalid
12
- end
13
-
14
- it 'should generate authorized_keys file' do
15
- Gritano::User.create(login: 'login').keys.create(key: "key", name: "name")
16
- Gritano::Key.authorized_keys.should match /^command=/
17
- end
18
- end
38
+ end
@@ -0,0 +1,72 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ module Gritano
4
+ describe Permission do
5
+
6
+ def create_permission(access)
7
+ permission = Permission.new
8
+ access.each do |a|
9
+ permission.add_access(a)
10
+ end
11
+ return permission
12
+ end
13
+
14
+ it "should add READ access" do
15
+ permission = create_permission([])
16
+ permission.add_access(:read)
17
+ permission.is(:read).should be_true
18
+ permission.is(:write).should be_false
19
+ end
20
+
21
+ it "should add WRITE access" do
22
+ permission = create_permission([])
23
+ permission.add_access(:write)
24
+ permission.is(:write).should be_true
25
+ permission.is(:read).should be_false
26
+ end
27
+
28
+ it "should add READ and WRITE access" do
29
+ permission = create_permission([])
30
+ permission.add_access(:read)
31
+ permission.add_access(:write)
32
+ permission.is(:write).should be_true
33
+ permission.is(:read).should be_true
34
+ end
35
+
36
+ it "should remove READ access" do
37
+ permission = create_permission([:read, :write])
38
+ permission.remove_access(:read)
39
+ permission.is(:read).should be_false
40
+ permission.is(:write).should be_true
41
+ end
42
+
43
+ it "should remove WRITE access" do
44
+ permission = create_permission([:read, :write])
45
+ permission.remove_access(:write)
46
+ permission.is(:write).should be_false
47
+ permission.is(:read).should be_true
48
+ end
49
+
50
+ it "should remove READ and WRITE access" do
51
+ permission = create_permission([:read, :write])
52
+ permission.remove_access(:write)
53
+ permission.remove_access(:read)
54
+ permission.is(:write).should be_false
55
+ permission.is(:read).should be_false
56
+ end
57
+
58
+ it "should not add wrong access" do
59
+ permission = create_permission([:read, :write])
60
+ permission.add_access(:wrong).should be_false
61
+ permission.is(:write).should be_true
62
+ permission.is(:read).should be_true
63
+ end
64
+
65
+ it "should not remove wrong access" do
66
+ permission = create_permission([:read, :write])
67
+ permission.remove_access(:wrong).should be_false
68
+ permission.is(:write).should be_true
69
+ permission.is(:read).should be_true
70
+ end
71
+ end
72
+ end
@@ -1,23 +1,56 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
- describe Gritano::Repository do
4
- it 'should have a name' do
5
- repo = Gritano::Repository.new
6
- repo.should be_invalid
7
- repo = Gritano::Repository.new(name: 'tmp/name.git')
8
- repo.should be_valid
9
- end
10
-
11
- it 'should have a unique name' do
12
- repo1 = Gritano::Repository.create(name: 'tmp/name.git')
13
- repo2 = Gritano::Repository.new(name: 'tmp/name.git')
14
- repo2.should be_invalid
15
- end
16
-
17
- it 'can have a path' do
18
- repo = Gritano::Repository.new(name: 'name.git', path: 'tmp')
19
- repo.should be_valid
20
- repo.save.should be_true
21
- repo.full_path.should be == 'tmp/name.git'
3
+ module Gritano
4
+ describe Repository do
5
+ def stub_hooks
6
+ Repository.any_instance.stub(:create_bare_repo).and_return(:create_bare_repo)
7
+ Repository.any_instance.stub(:destroy_bare_repo).and_return(:destroy_bare_repo)
8
+ end
9
+
10
+ it "should have a name" do
11
+ stub_hooks
12
+ repo = Repository.new(path: 'path')
13
+ repo.should be_invalid
14
+ end
15
+
16
+ it "should have a unique name" do
17
+ stub_hooks
18
+ repo = Repository.create(name:'myrepo', path: 'path')
19
+ repo.should be_valid
20
+ repo = Repository.create(name:'myrepo', path: 'path')
21
+ repo.should be_invalid
22
+ end
23
+
24
+ it "can have many users" do
25
+ stub_hooks
26
+ repo = Repository.create(name:'myrepo', path: 'path')
27
+ repo.users.create(login: 'login1')
28
+ repo.users.create(login: 'login2')
29
+ repo.users.count.should == 2
30
+ end
31
+
32
+ it "have a full path" do
33
+ stub_hooks
34
+ repo = Repository.create(name:'myrepo', path: 'path')
35
+ repo.full_path.should == 'path/myrepo'
36
+ end
37
+
38
+ it "have a full path even if it doesn't have a path" do
39
+ stub_hooks
40
+ repo = Repository.create(name:'myrepo')
41
+ repo.full_path.should == 'myrepo'
42
+ end
43
+
44
+ it "should create a bare repo when it is created" do
45
+ Grit::Repo.should_receive("init_bare").with('path/myrepo')
46
+ Repository.create(name:'myrepo', path: 'path')
47
+ end
48
+
49
+ it "should remove the repository when it is destroyed" do
50
+ Grit::Repo.should_receive("init_bare").with('path/myrepo')
51
+ FileUtils.should_receive("rm_r").with('path/myrepo', force: true)
52
+ repo = Repository.create(name:'myrepo', path: 'path')
53
+ repo.destroy
54
+ end
22
55
  end
23
56
  end