gritano 1.0.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (220) hide show
  1. data/Gemfile +9 -17
  2. data/Gemfile.lock +78 -50
  3. data/Guardfile +9 -0
  4. data/README.rdoc +23 -24
  5. data/Rakefile +8 -12
  6. data/TODO +12 -8
  7. data/VERSION +1 -1
  8. data/bin/gritano +8 -1
  9. data/bin/gritano-remote +16 -2
  10. data/gritano.gemspec +52 -230
  11. data/lib/gritano.rb +12 -6
  12. data/lib/gritano/config.rb +11 -31
  13. data/lib/gritano/console/base.rb +6 -74
  14. data/lib/gritano/console/git.rb +29 -0
  15. data/lib/gritano/console/local.rb +131 -0
  16. data/lib/gritano/console/remote.rb +47 -93
  17. data/lib/gritano/core/key.rb +18 -0
  18. data/lib/gritano/core/user.rb +12 -0
  19. data/lib/gritano/helpers.rb +52 -0
  20. data/lib/gritano/renderer.rb +36 -0
  21. data/lib/gritano/thor.rb +27 -0
  22. data/spec/data/development.yml +2 -0
  23. data/spec/gritano/console/git_spec.rb +55 -0
  24. data/spec/gritano/console/local_spec.rb +148 -0
  25. data/spec/gritano/console/remote_spec.rb +56 -0
  26. data/spec/gritano/core/key_spec.rb +21 -0
  27. data/spec/gritano/core/user_spec.rb +43 -0
  28. data/spec/gritano/helpers_spec.rb +113 -0
  29. data/spec/gritano/thor_spec.rb +29 -0
  30. data/spec/spec_helper.rb +1 -16
  31. data/templates/local.gritano +4 -0
  32. data/templates/remote.gritano +5 -0
  33. metadata +61 -280
  34. data/.gritano/config.yml +0 -2
  35. data/.gritano/database.yml +0 -2
  36. data/.ssh/.gitignore +0 -4
  37. data/bin/gritano-pub-key +0 -15
  38. data/db/migrate/001_create_users.rb +0 -8
  39. data/db/migrate/002_create_repositories.rb +0 -9
  40. data/db/migrate/003_create_permissions.rb +0 -10
  41. data/db/migrate/004_create_keys.rb +0 -11
  42. data/db/migrate/005_add_admin_to_users.rb +0 -10
  43. data/db/migrate/006_add_email_to_users.rb +0 -10
  44. data/db/migrate/007_add_password_to_users.rb +0 -10
  45. data/db/migrate/008_remove_password_from_user.rb +0 -10
  46. data/db/migrate/009_remove_email_from_users.rb +0 -10
  47. data/features/data/config_true.yml +0 -2
  48. data/features/data/local_commands/repo_add_tmp_jeka_git.txt +0 -1
  49. data/features/data/local_commands/repo_add_tmp_p_lang_git.txt +0 -1
  50. data/features/data/local_commands/repo_add_tmp_p_lang_git_igorbonadio.txt +0 -1
  51. data/features/data/local_commands/repo_add_tmp_p_lang_git_igorbonadio_jessicaeto.txt +0 -1
  52. data/features/data/local_commands/repo_list.txt +0 -6
  53. data/features/data/local_commands/repo_read_add_tmp_gritano_git_arybonadio.txt +0 -1
  54. data/features/data/local_commands/repo_read_add_tmp_gritano_git_jessicaeto.txt +0 -1
  55. data/features/data/local_commands/repo_read_add_tmp_p_lang_git_jessicaeto.txt +0 -1
  56. data/features/data/local_commands/repo_read_rm_tmp_jeka_git_aribonadio.txt +0 -1
  57. data/features/data/local_commands/repo_read_rm_tmp_jeka_git_igorbonadio.txt +0 -1
  58. data/features/data/local_commands/repo_read_rm_tmp_p_lang_git_igorbonadio.txt +0 -1
  59. data/features/data/local_commands/repo_rm_tmp_jeka_git.txt +0 -1
  60. data/features/data/local_commands/repo_rm_tmp_p_lang_git.txt +0 -1
  61. data/features/data/local_commands/repo_user_list_tmp_jeka_git.txt +0 -6
  62. data/features/data/local_commands/repo_user_list_tmp_ruby_git.txt +0 -1
  63. data/features/data/local_commands/repo_write_add_tmp_gritano_git_arybonadio.txt +0 -1
  64. data/features/data/local_commands/repo_write_add_tmp_gritano_git_jessicaeto.txt +0 -1
  65. data/features/data/local_commands/repo_write_add_tmp_p_lang_git_jessicaeto.txt +0 -1
  66. data/features/data/local_commands/repo_write_rm_tmp_gritano_git_arybonadio.txt +0 -1
  67. data/features/data/local_commands/repo_write_rm_tmp_gritano_git_igorbonadio.txt +0 -1
  68. data/features/data/local_commands/repo_write_rm_tmp_p_lang_git_igorbonadio.txt +0 -1
  69. data/features/data/local_commands/user_add_igorbonadio.txt +0 -1
  70. data/features/data/local_commands/user_add_jose.txt +0 -1
  71. data/features/data/local_commands/user_admin_add_arybonadio.txt +0 -1
  72. data/features/data/local_commands/user_admin_add_igorbonadio.txt +0 -1
  73. data/features/data/local_commands/user_admin_rm_arybonadio.txt +0 -1
  74. data/features/data/local_commands/user_admin_rm_igorbonadio.txt +0 -1
  75. data/features/data/local_commands/user_key_add_igorbonadio_marvin.txt +0 -1
  76. data/features/data/local_commands/user_key_add_userrr_marvino.txt +0 -1
  77. data/features/data/local_commands/user_key_list_arybonadio.txt +0 -1
  78. data/features/data/local_commands/user_key_list_igorbonadio.txt +0 -5
  79. data/features/data/local_commands/user_key_rm_igorbonadio_eva.txt +0 -1
  80. data/features/data/local_commands/user_key_rm_igorbonadio_marvino.txt +0 -1
  81. data/features/data/local_commands/user_list.txt +0 -6
  82. data/features/data/local_commands/user_repo_list_arybonadio.txt +0 -1
  83. data/features/data/local_commands/user_repo_list_igorbonadio.txt +0 -6
  84. data/features/data/local_commands/user_rm_igorbonadio.txt +0 -1
  85. data/features/data/local_commands/user_rm_jose.txt +0 -1
  86. data/features/data/local_commands/version.txt +0 -1
  87. data/features/data/local_help.txt +0 -32
  88. data/features/data/remote_commands/admin_help_igorbonadio.txt +0 -32
  89. data/features/data/remote_commands/admin_help_jessicaeto.txt +0 -32
  90. data/features/data/remote_commands/admin_repo_add_tmp_jeka_git_igorbonadio.txt +0 -1
  91. data/features/data/remote_commands/admin_repo_add_tmp_jeka_git_jessicaeto.txt +0 -1
  92. data/features/data/remote_commands/admin_repo_add_tmp_p_lang_git_igorbonadio.txt +0 -1
  93. data/features/data/remote_commands/admin_repo_add_tmp_p_lang_git_igorbonadio_igorbonadio.txt +0 -1
  94. data/features/data/remote_commands/admin_repo_add_tmp_p_lang_git_igorbonadio_jessicaeto.txt +0 -1
  95. data/features/data/remote_commands/admin_repo_add_tmp_p_lang_git_igorbonadio_jessicaeto_igorbonadio.txt +0 -1
  96. data/features/data/remote_commands/admin_repo_add_tmp_p_lang_git_igorbonadio_jessicaeto_jessicaeto.txt +0 -1
  97. data/features/data/remote_commands/admin_repo_add_tmp_p_lang_git_jessicaeto.txt +0 -1
  98. data/features/data/remote_commands/admin_repo_list_igorbonadio.txt +0 -6
  99. data/features/data/remote_commands/admin_repo_list_jessicaeto.txt +0 -1
  100. data/features/data/remote_commands/admin_repo_read_add_tmp_gritano_git_arybonadio_igorbonadio.txt +0 -1
  101. data/features/data/remote_commands/admin_repo_read_add_tmp_gritano_git_arybonadio_jessicaeto.txt +0 -1
  102. data/features/data/remote_commands/admin_repo_read_add_tmp_gritano_git_jessicaeto_igorbonadio.txt +0 -1
  103. data/features/data/remote_commands/admin_repo_read_add_tmp_gritano_git_jessicaeto_jessicaeto.txt +0 -1
  104. data/features/data/remote_commands/admin_repo_read_add_tmp_p_lang_git_jessicaeto_igorbonadio.txt +0 -1
  105. data/features/data/remote_commands/admin_repo_read_add_tmp_p_lang_git_jessicaeto_jessicaeto.txt +0 -1
  106. data/features/data/remote_commands/admin_repo_read_rm_tmp_jeka_git_aribonadio_igorbonadio.txt +0 -1
  107. data/features/data/remote_commands/admin_repo_read_rm_tmp_jeka_git_aribonadio_jessicaeto.txt +0 -1
  108. data/features/data/remote_commands/admin_repo_read_rm_tmp_jeka_git_igorbonadio_igorbonadio.txt +0 -1
  109. data/features/data/remote_commands/admin_repo_read_rm_tmp_jeka_git_igorbonadio_jessicaeto.txt +0 -1
  110. data/features/data/remote_commands/admin_repo_read_rm_tmp_p_lang_git_igorbonadio_igorbonadio.txt +0 -1
  111. data/features/data/remote_commands/admin_repo_read_rm_tmp_p_lang_git_igorbonadio_jessicaeto.txt +0 -1
  112. data/features/data/remote_commands/admin_repo_rm_tmp_jeka_git_igorbonadio.txt +0 -1
  113. data/features/data/remote_commands/admin_repo_rm_tmp_jeka_git_jessicaeto.txt +0 -1
  114. data/features/data/remote_commands/admin_repo_rm_tmp_p_lang_git_igorbonadio.txt +0 -1
  115. data/features/data/remote_commands/admin_repo_rm_tmp_p_lang_git_jessicaeto.txt +0 -1
  116. data/features/data/remote_commands/admin_repo_user_list_tmp_jeka_git_igorbonadio.txt +0 -6
  117. data/features/data/remote_commands/admin_repo_user_list_tmp_jeka_git_jessicaeto.txt +0 -1
  118. data/features/data/remote_commands/admin_repo_user_list_tmp_ruby_git_igorbonadio.txt +0 -1
  119. data/features/data/remote_commands/admin_repo_user_list_tmp_ruby_git_jessicaeto.txt +0 -1
  120. data/features/data/remote_commands/admin_repo_write_add_tmp_gritano_git_arybonadio_igorbonadio.txt +0 -1
  121. data/features/data/remote_commands/admin_repo_write_add_tmp_gritano_git_arybonadio_jessicaeto.txt +0 -1
  122. data/features/data/remote_commands/admin_repo_write_add_tmp_gritano_git_jessicaeto_igorbonadio.txt +0 -1
  123. data/features/data/remote_commands/admin_repo_write_add_tmp_gritano_git_jessicaeto_jessicaeto.txt +0 -1
  124. data/features/data/remote_commands/admin_repo_write_add_tmp_p_lang_git_jessicaeto_igorbonadio.txt +0 -1
  125. data/features/data/remote_commands/admin_repo_write_add_tmp_p_lang_git_jessicaeto_jessicaeto.txt +0 -1
  126. data/features/data/remote_commands/admin_repo_write_rm_tmp_gritano_git_arybonadio_igorbonadio.txt +0 -1
  127. data/features/data/remote_commands/admin_repo_write_rm_tmp_gritano_git_arybonadio_jessicaeto.txt +0 -1
  128. data/features/data/remote_commands/admin_repo_write_rm_tmp_gritano_git_igorbonadio_igorbonadio.txt +0 -1
  129. data/features/data/remote_commands/admin_repo_write_rm_tmp_gritano_git_igorbonadio_jessicaeto.txt +0 -1
  130. data/features/data/remote_commands/admin_repo_write_rm_tmp_p_lang_git_igorbonadio_igorbonadio.txt +0 -1
  131. data/features/data/remote_commands/admin_repo_write_rm_tmp_p_lang_git_igorbonadio_jessicaeto.txt +0 -1
  132. data/features/data/remote_commands/admin_user_add_igorbonadio_igorbonadio.txt +0 -1
  133. data/features/data/remote_commands/admin_user_add_igorbonadio_jessicaeto.txt +0 -1
  134. data/features/data/remote_commands/admin_user_add_jose_igorbonadio.txt +0 -1
  135. data/features/data/remote_commands/admin_user_add_jose_jessicaeto.txt +0 -1
  136. data/features/data/remote_commands/admin_user_admin_add_arybonadio_igorbonadio.txt +0 -1
  137. data/features/data/remote_commands/admin_user_admin_add_arybonadio_jessicaeto.txt +0 -1
  138. data/features/data/remote_commands/admin_user_admin_add_igorbonadio_igorbonadio.txt +0 -1
  139. data/features/data/remote_commands/admin_user_admin_add_igorbonadio_jessicaeto.txt +0 -1
  140. data/features/data/remote_commands/admin_user_admin_rm_arybonadio_igorbonadio.txt +0 -1
  141. data/features/data/remote_commands/admin_user_admin_rm_arybonadio_jessicaeto.txt +0 -1
  142. data/features/data/remote_commands/admin_user_admin_rm_igorbonadio_igorbonadio.txt +0 -1
  143. data/features/data/remote_commands/admin_user_admin_rm_igorbonadio_jessicaeto.txt +0 -1
  144. data/features/data/remote_commands/admin_user_key_add_igorbonadio_marvin_igorbonadio.txt +0 -1
  145. data/features/data/remote_commands/admin_user_key_add_igorbonadio_marvin_jessicaeto.txt +0 -1
  146. data/features/data/remote_commands/admin_user_key_add_userrr_marvino_igorbonadio.txt +0 -1
  147. data/features/data/remote_commands/admin_user_key_add_userrr_marvino_jessicaeto.txt +0 -1
  148. data/features/data/remote_commands/admin_user_key_list_arybonadio_igorbonadio.txt +0 -1
  149. data/features/data/remote_commands/admin_user_key_list_arybonadio_jessicaeto.txt +0 -1
  150. data/features/data/remote_commands/admin_user_key_list_igorbonadio_igorbonadio.txt +0 -5
  151. data/features/data/remote_commands/admin_user_key_list_igorbonadio_jessicaeto.txt +0 -1
  152. data/features/data/remote_commands/admin_user_key_rm_igorbonadio_eva_igorbonadio.txt +0 -1
  153. data/features/data/remote_commands/admin_user_key_rm_igorbonadio_eva_jessicaeto.txt +0 -1
  154. data/features/data/remote_commands/admin_user_key_rm_igorbonadio_marvino_igorbonadio.txt +0 -1
  155. data/features/data/remote_commands/admin_user_key_rm_igorbonadio_marvino_jessicaeto.txt +0 -1
  156. data/features/data/remote_commands/admin_user_list_igorbonadio.txt +0 -6
  157. data/features/data/remote_commands/admin_user_list_jessicaeto.txt +0 -1
  158. data/features/data/remote_commands/admin_user_repo_list_arybonadio_igorbonadio.txt +0 -1
  159. data/features/data/remote_commands/admin_user_repo_list_arybonadio_jessicaeto.txt +0 -1
  160. data/features/data/remote_commands/admin_user_repo_list_igorbonadio_igorbonadio.txt +0 -6
  161. data/features/data/remote_commands/admin_user_repo_list_igorbonadio_jessicaeto.txt +0 -1
  162. data/features/data/remote_commands/admin_user_rm_igorbonadio_igorbonadio.txt +0 -1
  163. data/features/data/remote_commands/admin_user_rm_igorbonadio_jessicaeto.txt +0 -1
  164. data/features/data/remote_commands/admin_user_rm_jose_igorbonadio.txt +0 -1
  165. data/features/data/remote_commands/admin_user_rm_jose_jessicaeto.txt +0 -1
  166. data/features/data/remote_commands/admin_version_igorbonadio.txt +0 -1
  167. data/features/data/remote_commands/admin_version_jessicaeto.txt +0 -1
  168. data/features/data/remote_commands/email_get_igorbonadio.txt +0 -1
  169. data/features/data/remote_commands/email_get_jessicaeto.txt +0 -1
  170. data/features/data/remote_commands/email_update_email@server_com_igorbonadio.txt +0 -1
  171. data/features/data/remote_commands/email_update_email@server_com_jessicaeto.txt +0 -1
  172. data/features/data/remote_commands/help_igorbonadio.txt +0 -14
  173. data/features/data/remote_commands/help_jessicaeto.txt +0 -14
  174. data/features/data/remote_commands/invalid_command_igorbonadio.txt +0 -14
  175. data/features/data/remote_commands/invalid_command_jessicaeto.txt +0 -14
  176. data/features/data/remote_commands/key_add_keyname_igorbonadio.txt +0 -1
  177. data/features/data/remote_commands/key_add_keyname_jessicaeto.txt +0 -1
  178. data/features/data/remote_commands/key_list_igorbonadio.txt +0 -5
  179. data/features/data/remote_commands/key_list_jessicaeto.txt +0 -5
  180. data/features/data/remote_commands/key_rm_hal_igorbonadio.txt +0 -1
  181. data/features/data/remote_commands/key_rm_hal_jessicaeto.txt +0 -1
  182. data/features/data/remote_commands/repo_list_igorbonadio.txt +0 -6
  183. data/features/data/remote_commands/repo_list_jessicaeto.txt +0 -5
  184. data/features/data/remote_commands/version_igorbonadio.txt +0 -1
  185. data/features/data/remote_commands/version_jessicaeto.txt +0 -1
  186. data/features/data/remote_help.txt +0 -14
  187. data/features/install.feature +0 -40
  188. data/features/local.feature +0 -80
  189. data/features/pub_key.feature +0 -25
  190. data/features/remote.feature +0 -150
  191. data/features/step_definitions/background_step.rb +0 -26
  192. data/features/step_definitions/install_step.rb +0 -30
  193. data/features/step_definitions/local_step.rb +0 -25
  194. data/features/step_definitions/pub_key_step.rb +0 -15
  195. data/features/step_definitions/remote_step.rb +0 -49
  196. data/features/support/database_cleaner.rb +0 -15
  197. data/features/support/env.rb +0 -30
  198. data/lib/gritano/cli.rb +0 -49
  199. data/lib/gritano/console.rb +0 -26
  200. data/lib/gritano/console/executor.rb +0 -298
  201. data/lib/gritano/console/gritano.rb +0 -35
  202. data/lib/gritano/console/installer.rb +0 -55
  203. data/lib/gritano/models.rb +0 -7
  204. data/lib/gritano/models/key.rb +0 -37
  205. data/lib/gritano/models/permission.rb +0 -39
  206. data/lib/gritano/models/repository.rb +0 -29
  207. data/lib/gritano/models/user.rb +0 -39
  208. data/spec/cli_spec.rb +0 -26
  209. data/spec/config_spec.rb +0 -64
  210. data/spec/console_base_spec.rb +0 -61
  211. data/spec/console_executor_spec.rb +0 -183
  212. data/spec/console_gritano_spec.rb +0 -121
  213. data/spec/console_installer_spec.rb +0 -28
  214. data/spec/console_remote_spec.rb +0 -70
  215. data/spec/console_spec.rb +0 -27
  216. data/spec/data/help_command_name.txt +0 -7
  217. data/spec/model_key_spec.rb +0 -44
  218. data/spec/model_permission_spec.rb +0 -72
  219. data/spec/model_repository_spec.rb +0 -56
  220. data/spec/model_user_spec.rb +0 -96
@@ -0,0 +1,18 @@
1
+ module Gritano
2
+ module Core
3
+ class Key
4
+ after_create :update_authorized_keys
5
+
6
+ def update_authorized_keys
7
+ authorized_keys = File.join(Etc.getpwuid.dir, '.ssh/authorized_keys')
8
+ File.open(authorized_keys, "w").write(Key.authorized_keys)
9
+ end
10
+
11
+ def self.authorized_keys
12
+ Key.all.map do |key|
13
+ "command=\"gritano-remote #{key.user.login}\" #{key.key}"
14
+ end.join("\n")
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,12 @@
1
+ module Gritano
2
+ module Core
3
+ class User
4
+ def access(repo)
5
+ access = []
6
+ access << 'read' if check_access(repo, :read)
7
+ access << 'write' if check_access(repo, :write)
8
+ "#{access.join('+')}"
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,52 @@
1
+ module Gritano
2
+ module CLI
3
+ module Helpers
4
+ def create_model(model, params)
5
+ instance = model.new(params)
6
+ if instance.save
7
+ render_text "#{model.name.split(':')[-1].downcase} was successfully created."
8
+ else
9
+ render_text "an error occurred."
10
+ end
11
+ end
12
+
13
+ def update_model(instance, params)
14
+ if instance.update_attributes(params)
15
+ render_text "#{instance.class.name.split(':')[-1].downcase} was successfully updated."
16
+ else
17
+ render_text "an error occurred."
18
+ end
19
+ end
20
+
21
+ def destroy_model(model, params)
22
+ instance = model.where(params).first
23
+ if instance
24
+ instance.destroy
25
+ render_text "#{model.name.split(':')[-1].downcase} was successfully destroyed."
26
+ else
27
+ render_text "#{model.name.split(':')[-1].downcase} doens't exist."
28
+ end
29
+ end
30
+
31
+ def use_if_not_nil(*variables, &block)
32
+ unless variables.index(nil)
33
+ block.call(*variables)
34
+ else
35
+ render_text "an error occurred"
36
+ end
37
+ end
38
+
39
+ def try_change_access(user, repo, add_or_rm, read_or_write)
40
+ if user.send("#{add_or_rm}_access", repo, read_or_write)
41
+ render_text "done"
42
+ else
43
+ render_text "an error occurred"
44
+ end
45
+ end
46
+
47
+ def valid_options?(options)
48
+ true unless options.empty?
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,36 @@
1
+ module Gritano
2
+ module CLI
3
+ module Renderer
4
+ def render_text(text)
5
+ puts text
6
+ end
7
+
8
+ def render_table(elements, *attributes)
9
+ attributes_hash = {}
10
+ attributes.each do |a|
11
+ if a.respond_to?(:keys)
12
+ attributes_hash = attributes_hash.merge(a)
13
+ else
14
+ attributes_hash[a] = nil
15
+ end
16
+ end
17
+ table = Terminal::Table.new do |t|
18
+ t << attributes_hash.map { |key, value| key }
19
+ t << :separator
20
+ elements.each do |element|
21
+ row = []
22
+ attributes_hash.each do |attribute, params|
23
+ if params
24
+ row << element.send(attribute, params)
25
+ else
26
+ row << element.send(attribute)
27
+ end
28
+ end
29
+ t.add_row row
30
+ end
31
+ end
32
+ render_text table
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,27 @@
1
+ require 'thor'
2
+
3
+ module Gritano
4
+ module CLI
5
+ class Thor < Thor
6
+ def self.define_task(name, description="", &block)
7
+ params = block.parameters.map { |type, name| name.upcase }.join(' ')
8
+ desc("#{name} #{params}".rstrip, description)
9
+ bf = before_filters
10
+ define_method(name.to_sym) do |*params|
11
+ instance_eval(&bf[name]) if bf[name]
12
+ instance_exec(*params, &block)
13
+ end
14
+ end
15
+
16
+ def self.before(methods, &block)
17
+ methods.each do |method|
18
+ before_filters[method] = block
19
+ end
20
+ end
21
+
22
+ def self.before_filters
23
+ @before_filters ||= {}
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,2 @@
1
+ adapter: sqlite3
2
+ database: tmp/development.sqlite3
@@ -0,0 +1,55 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ module Gritano::CLI::Console
4
+ describe Git do
5
+ before(:each) do
6
+ $stdout.stub(:puts)
7
+ $stdin.stub(:readlines).and_return(['some pubkey'])
8
+ ActiveRecord::Base.stub(:establish_connection)
9
+ YAML.stub(:load)
10
+ Gritano::CLI::Config.remote_user = 'user_login'
11
+ end
12
+
13
+ it "should execute git-receive-pack if the user has write access" do
14
+ user = double('User')
15
+ repo = double('Repository')
16
+ Gritano::Core::User.should_receive(:where).with(login: 'user_login').and_return([user])
17
+ Gritano::Core::Repository.should_receive(:where).with(name: 'repo.git').and_return([repo])
18
+ user.should_receive(:check_access).with(repo, :write).and_return(true)
19
+ repo.should_receive(:full_path).and_return('folder/repo.git')
20
+ Kernel.should_receive(:exec).with("git-receive-pack 'folder/repo.git'")
21
+ Gritano::CLI::Console::Git.start %w{git:receive:pack repo.git}
22
+ end
23
+
24
+ it "should not execute git-receive-pack if the user has not write access" do
25
+ user = double('User')
26
+ repo = double('Repository')
27
+ Gritano::Core::User.should_receive(:where).with(login: 'user_login').and_return([user])
28
+ Gritano::Core::Repository.should_receive(:where).with(name: 'repo.git').and_return([repo])
29
+ user.should_receive(:check_access).with(repo, :write).and_return(false)
30
+ Kernel.should_not_receive(:exec).with("git-receive-pack 'folder/repo.git'")
31
+ Gritano::CLI::Console::Git.start %w{git:receive:pack repo.git}
32
+ end
33
+
34
+ it "should execute git-upload-pack if the user has read access" do
35
+ user = double('User')
36
+ repo = double('Repository')
37
+ Gritano::Core::User.should_receive(:where).with(login: 'user_login').and_return([user])
38
+ Gritano::Core::Repository.should_receive(:where).with(name: 'repo.git').and_return([repo])
39
+ user.should_receive(:check_access).with(repo, :read).and_return(true)
40
+ repo.should_receive(:full_path).and_return('folder/repo.git')
41
+ Kernel.should_receive(:exec).with("git-upload-pack 'folder/repo.git'")
42
+ Gritano::CLI::Console::Git.start %w{git:upload:pack repo.git}
43
+ end
44
+
45
+ it "should not execute git-upload-pack if the user has not read access" do
46
+ user = double('User')
47
+ repo = double('Repository')
48
+ Gritano::Core::User.should_receive(:where).with(login: 'user_login').and_return([user])
49
+ Gritano::Core::Repository.should_receive(:where).with(name: 'repo.git').and_return([repo])
50
+ user.should_receive(:check_access).with(repo, :read).and_return(false)
51
+ Kernel.should_not_receive(:exec).with("git-upload-pack 'folder/repo.git'")
52
+ Gritano::CLI::Console::Git.start %w{git:upload:pack repo.git}
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,148 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ module Gritano::CLI::Console
4
+ describe Local do
5
+
6
+ before(:each) do
7
+ $stdout.stub(:puts)
8
+ $stdin.stub(:readlines).and_return(['some pubkey'])
9
+ ActiveRecord::Base.stub(:establish_connection)
10
+ YAML.stub(:load)
11
+ end
12
+
13
+ describe "#user" do
14
+ it "should list all users ordered by login" do
15
+ Gritano::Core::User.should_receive(:order).with(:login).and_return([])
16
+ Gritano::CLI::Console::Local.start %w{user:list}
17
+ end
18
+
19
+ it "should add a user" do
20
+ user = double("User")
21
+ user.should_receive(:save).and_return(true)
22
+ Gritano::Core::User.should_receive(:new).with(login: 'user_login').and_return(user)
23
+ Gritano::CLI::Console::Local.start %w{user:add user_login}
24
+ end
25
+
26
+ it "should remove an existing user" do
27
+ user = double("User")
28
+ user.should_receive(:destroy)
29
+ Gritano::Core::User.should_receive(:where).with(login: 'user_login').and_return([user])
30
+ Gritano::CLI::Console::Local.start %w{user:rm user_login}
31
+ end
32
+
33
+ it "should update the admin attribute of an existing user" do
34
+ user = double("User")
35
+ user.should_receive(:update_attributes).with({"admin" => "true"})
36
+ Gritano::Core::User.should_receive(:where).with(login: 'user_login').and_return([user])
37
+ Gritano::CLI::Console::Local.start %w{user:update user_login --admin=true}
38
+ end
39
+
40
+ describe "#keys" do
41
+ it "should list user's keys ordered by name" do
42
+ user = double("User")
43
+ keys = double("Key")
44
+ keys.stub(:count).and_return(10)
45
+ keys.stub(:each)
46
+ Gritano::Core::User.should_receive(:where).with(login: 'user_login').and_return([user])
47
+ user.should_receive(:keys).and_return(keys)
48
+ keys.should_receive(:order).with(:name).and_return(keys)
49
+ Gritano::CLI::Console::Local.start %w{user:key:list user_login}
50
+ end
51
+
52
+ it "should add user's key" do
53
+ user = double("User")
54
+ keys = double("Key")
55
+ keys.stub(:name).and_return("Key")
56
+ key = double("Key")
57
+ Gritano::Core::User.should_receive(:where).with(login: 'user_login').and_return([user])
58
+ user.should_receive(:keys).and_return(keys)
59
+ keys.should_receive(:new).with(name: 'user_key', key: 'some pubkey').and_return(key)
60
+ key.should_receive(:save).and_return(true)
61
+ Gritano::CLI::Console::Local.start %w{user:key:add user_login user_key}
62
+ end
63
+
64
+ it "should remove user's key" do
65
+ user = double("User")
66
+ keys = [double("Key")]
67
+ keys.stub(:name).and_return("Key")
68
+ key = double("Key")
69
+ Gritano::Core::User.should_receive(:where).with(login: 'user_login').and_return([user])
70
+ user.should_receive(:keys).and_return(keys)
71
+ keys.should_receive(:where).with(name: 'user_key').and_return([key])
72
+ key.should_receive(:destroy)
73
+ Gritano::CLI::Console::Local.start %w{user:key:rm user_login user_key}
74
+ end
75
+ end
76
+ end
77
+
78
+ describe "#repo" do
79
+ it "should list repositories ordered by name" do
80
+ Gritano::Core::Repository.should_receive(:order).with(:name).and_return([])
81
+ Gritano::CLI::Console::Local.start %w{repo:list}
82
+ end
83
+
84
+ it "should add a new repository" do
85
+ repo = double("Repository")
86
+ repo.should_receive(:save).and_return(true)
87
+ Gritano::CLI::Config.repository_path = "tmp"
88
+ Gritano::Core::Repository.should_receive(:new).with(name: 'repo.git', path: 'tmp').and_return(repo)
89
+ Gritano::CLI::Console::Local.start %w{repo:add repo.git}
90
+ end
91
+
92
+ it "should remove a existing repository" do
93
+ repo = double("Repository")
94
+ repo.should_receive(:destroy)
95
+ Gritano::Core::Repository.should_receive(:where).with(name: 'repo.git').and_return([repo])
96
+ Gritano::CLI::Console::Local.start %w{repo:rm repo.git}
97
+ end
98
+
99
+ it "should add read access to a repository" do
100
+ repo = double("Repository")
101
+ user = double("User")
102
+ Gritano::Core::Repository.should_receive(:where).with(name: 'repo.git').and_return([repo])
103
+ Gritano::Core::User.should_receive(:where).with(login: 'user_login').and_return([user])
104
+ user.should_receive(:add_access).with(repo, :read).and_return(true)
105
+ Gritano::CLI::Console::Local.start %w{repo:read:add repo.git user_login}
106
+ end
107
+
108
+ it "should remove read access from a repository" do
109
+ repo = double("Repository")
110
+ user = double("User")
111
+ Gritano::Core::Repository.should_receive(:where).with(name: 'repo.git').and_return([repo])
112
+ Gritano::Core::User.should_receive(:where).with(login: 'user_login').and_return([user])
113
+ user.should_receive(:remove_access).with(repo, :read).and_return(true)
114
+ Gritano::CLI::Console::Local.start %w{repo:read:rm repo.git user_login}
115
+ end
116
+
117
+ it "should add write access to a repository" do
118
+ repo = double("Repository")
119
+ user = double("User")
120
+ Gritano::Core::Repository.should_receive(:where).with(name: 'repo.git').and_return([repo])
121
+ Gritano::Core::User.should_receive(:where).with(login: 'user_login').and_return([user])
122
+ user.should_receive(:add_access).with(repo, :write).and_return(true)
123
+ Gritano::CLI::Console::Local.start %w{repo:write:add repo.git user_login}
124
+ end
125
+
126
+ it "should remove write access from a repository" do
127
+ repo = double("Repository")
128
+ user = double("User")
129
+ Gritano::Core::Repository.should_receive(:where).with(name: 'repo.git').and_return([repo])
130
+ Gritano::Core::User.should_receive(:where).with(login: 'user_login').and_return([user])
131
+ user.should_receive(:remove_access).with(repo, :write).and_return(true)
132
+ Gritano::CLI::Console::Local.start %w{repo:write:rm repo.git user_login}
133
+ end
134
+
135
+ it "should list repository's users ordered by login" do
136
+ repo = double("Repository")
137
+ users = [double("User")]
138
+ user = double("User")
139
+ Gritano::Core::Repository.should_receive(:where).with(name: 'repo.git').and_return([repo])
140
+ repo.should_receive(:users).and_return(users)
141
+ users.should_receive(:order).with(:login).and_return([user])
142
+ user.should_receive(:access).with(repo)
143
+ user.stub(:login)
144
+ Gritano::CLI::Console::Local.start %w{repo:user:list repo.git}
145
+ end
146
+ end
147
+ end
148
+ end
@@ -0,0 +1,56 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ module Gritano::CLI::Console
4
+ describe Remote do
5
+
6
+ before(:each) do
7
+ $stdout.stub(:puts)
8
+ $stdin.stub(:readlines).and_return(['some pubkey'])
9
+ ActiveRecord::Base.stub(:establish_connection)
10
+ YAML.stub(:load)
11
+ Gritano::CLI::Config.remote_user = "user_login"
12
+ end
13
+
14
+ it "should list user's repositories" do
15
+ user = double('User')
16
+ repos = double('Repositories')
17
+ user.should_receive(:repositories).and_return(repos)
18
+ repos.should_receive(:order).with(:name).and_return([])
19
+ Gritano::Core::User.should_receive(:where).with(login: 'user_login').and_return([user])
20
+ Gritano::CLI::Console::Remote.start %w{repo:list}
21
+ end
22
+
23
+ it "should list user's keys ordered by name" do
24
+ user = double('User')
25
+ keys = double('Keys')
26
+ user.should_receive(:keys).and_return(keys)
27
+ keys.should_receive(:order).with(:name).and_return([])
28
+ Gritano::Core::User.should_receive(:where).with(login: 'user_login').and_return([user])
29
+ Gritano::CLI::Console::Remote.start %w{key:list}
30
+ end
31
+
32
+ it "should add user's key" do
33
+ user = double("User")
34
+ keys = double("Key")
35
+ keys.stub(:name).and_return("Key")
36
+ key = double("Key")
37
+ Gritano::Core::User.should_receive(:where).with(login: 'user_login').and_return([user])
38
+ user.should_receive(:keys).and_return(keys)
39
+ keys.should_receive(:new).with(name: 'user_key', key: 'some pubkey').and_return(key)
40
+ key.should_receive(:save).and_return(true)
41
+ Gritano::CLI::Console::Remote.start %w{key:add user_key}
42
+ end
43
+
44
+ it "should remove user's key" do
45
+ user = double("User")
46
+ keys = [double("Key")]
47
+ keys.stub(:name).and_return("Key")
48
+ key = double("Key")
49
+ Gritano::Core::User.should_receive(:where).with(login: 'user_login').and_return([user])
50
+ user.should_receive(:keys).and_return(keys)
51
+ keys.should_receive(:where).with(name: 'user_key').and_return([key])
52
+ key.should_receive(:destroy)
53
+ Gritano::CLI::Console::Remote.start %w{key:rm user_key}
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,21 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ module Gritano::Core
4
+ describe Key do
5
+ before(:all) do
6
+ ActiveRecord::Base.establish_connection(YAML::load(File.open('spec/data/development.yml')))
7
+ end
8
+
9
+ it "should generate the authorized_keys file" do
10
+ user = double("User")
11
+ user.stub(:login).and_return('user_login')
12
+ keys = [double("Key#1"), double("key#2")]
13
+ keys[0].stub(:user).and_return(user)
14
+ keys[0].stub(:key).and_return("some_key")
15
+ keys[1].stub(:user).and_return(user)
16
+ keys[1].stub(:key).and_return("some_key")
17
+ Key.stub(:all).and_return(keys)
18
+ Key.authorized_keys.should be == "command=\"gritano-remote user_login\" some_key\ncommand=\"gritano-remote user_login\" some_key"
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,43 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ module Gritano::Core
4
+ describe User do
5
+ before(:all) do
6
+ ActiveRecord::Base.establish_connection(YAML::load(File.open('spec/data/development.yml')))
7
+ end
8
+
9
+ describe "#access" do
10
+ it "should return a string that represents a read access" do
11
+ repo = double("Repo")
12
+ user = User.new
13
+ user.should_receive(:check_access).with(repo, :read).and_return(true)
14
+ user.should_receive(:check_access).with(repo, :write).and_return(false)
15
+ user.access(repo).should be == "read"
16
+ end
17
+
18
+ it "should return a string that represents a write access" do
19
+ repo = double("Repo")
20
+ user = User.new
21
+ user.should_receive(:check_access).with(repo, :read).and_return(false)
22
+ user.should_receive(:check_access).with(repo, :write).and_return(true)
23
+ user.access(repo).should be == "write"
24
+ end
25
+
26
+ it "should return a string that represents a read and write access" do
27
+ repo = double("Repo")
28
+ user = User.new
29
+ user.should_receive(:check_access).with(repo, :read).and_return(true)
30
+ user.should_receive(:check_access).with(repo, :write).and_return(true)
31
+ user.access(repo).should be == "read+write"
32
+ end
33
+
34
+ it "should return a null string when user doens't have access to the repository" do
35
+ repo = double("Repo")
36
+ user = User.new
37
+ user.should_receive(:check_access).with(repo, :read).and_return(false)
38
+ user.should_receive(:check_access).with(repo, :write).and_return(false)
39
+ user.access(repo).should be == ""
40
+ end
41
+ end
42
+ end
43
+ end