git_wit 0.0.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.
- data/MIT-LICENSE +20 -0
- data/README.md +82 -0
- data/Rakefile +40 -0
- data/app/controllers/git_wit/application_controller.rb +6 -0
- data/app/controllers/git_wit/git_controller.rb +116 -0
- data/bin/gw-shell +4 -0
- data/config/initializers/git_wit.rb +2 -0
- data/config/routes.rb +5 -0
- data/lib/generators/git_wit/install/USAGE +8 -0
- data/lib/generators/git_wit/install/install_generator.rb +15 -0
- data/lib/generators/git_wit/templates/README +11 -0
- data/lib/generators/git_wit/templates/git_wit.rb +78 -0
- data/lib/git_wit/auth.rb +28 -0
- data/lib/git_wit/authorized_keys.rb +102 -0
- data/lib/git_wit/engine.rb +12 -0
- data/lib/git_wit/errors.rb +6 -0
- data/lib/git_wit/shell.rb +72 -0
- data/lib/git_wit/version.rb +3 -0
- data/lib/git_wit.rb +38 -0
- data/test/dummy/README.rdoc +261 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/javascripts/application.js +16 -0
- data/test/dummy/app/assets/javascripts/bootstrap.js +5 -0
- data/test/dummy/app/assets/javascripts/public_keys.js +2 -0
- data/test/dummy/app/assets/javascripts/repositories.js +2 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/assets/stylesheets/bootstrap_and_overrides.css +12 -0
- data/test/dummy/app/assets/stylesheets/public_keys.css +4 -0
- data/test/dummy/app/assets/stylesheets/repositories.css +4 -0
- data/test/dummy/app/assets/stylesheets/scaffold.css +56 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/controllers/public_keys_controller.rb +61 -0
- data/test/dummy/app/controllers/repositories_controller.rb +76 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/helpers/public_keys_helper.rb +2 -0
- data/test/dummy/app/helpers/repositories_helper.rb +2 -0
- data/test/dummy/app/models/ability.rb +16 -0
- data/test/dummy/app/models/public_key.rb +46 -0
- data/test/dummy/app/models/repository.rb +27 -0
- data/test/dummy/app/models/role.rb +6 -0
- data/test/dummy/app/models/user.rb +14 -0
- data/test/dummy/app/views/devise/confirmations/new.html.erb +22 -0
- data/test/dummy/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
- data/test/dummy/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
- data/test/dummy/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
- data/test/dummy/app/views/devise/passwords/edit.html.erb +30 -0
- data/test/dummy/app/views/devise/passwords/new.html.erb +22 -0
- data/test/dummy/app/views/devise/registrations/edit.html.erb +50 -0
- data/test/dummy/app/views/devise/registrations/new.html.erb +43 -0
- data/test/dummy/app/views/devise/sessions/new.html.erb +37 -0
- data/test/dummy/app/views/devise/shared/_links.erb +29 -0
- data/test/dummy/app/views/devise/unlocks/new.html.erb +12 -0
- data/test/dummy/app/views/layouts/application.html.erb +106 -0
- data/test/dummy/app/views/public_keys/_form.html.erb +16 -0
- data/test/dummy/app/views/public_keys/index.html.erb +36 -0
- data/test/dummy/app/views/public_keys/new.html.erb +5 -0
- data/test/dummy/app/views/public_keys/show.html.erb +25 -0
- data/test/dummy/app/views/repositories/_form.html.erb +29 -0
- data/test/dummy/app/views/repositories/edit.html.erb +5 -0
- data/test/dummy/app/views/repositories/index.html.erb +52 -0
- data/test/dummy/app/views/repositories/new.html.erb +5 -0
- data/test/dummy/app/views/repositories/show.html.erb +31 -0
- data/test/dummy/config/application.rb +59 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +67 -0
- data/test/dummy/config/environments/test.rb +37 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/devise.rb +242 -0
- data/test/dummy/config/initializers/git_wit.rb +73 -0
- data/test/dummy/config/initializers/inflections.rb +15 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/rolify.rb +8 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/devise.en.yml +59 -0
- data/test/dummy/config/locales/en.bootstrap.yml +17 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +12 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/migrate/20130217110616_devise_create_users.rb +46 -0
- data/test/dummy/db/migrate/20130217111055_create_repositories.rb +14 -0
- data/test/dummy/db/migrate/20130217114405_rolify_create_roles.rb +19 -0
- data/test/dummy/db/migrate/20130217191808_add_username_to_users.rb +5 -0
- data/test/dummy/db/migrate/20130217221157_create_public_keys.rb +13 -0
- data/test/dummy/db/schema.rb +76 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +25 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/dummy/test/fixtures/public_keys.yml +14 -0
- data/test/dummy/test/fixtures/repositories.yml +17 -0
- data/test/dummy/test/fixtures/users.yml +9 -0
- data/test/dummy/test/functional/public_keys_controller_test.rb +49 -0
- data/test/dummy/test/functional/repositories_controller_test.rb +49 -0
- data/test/dummy/test/unit/helpers/public_keys_helper_test.rb +4 -0
- data/test/dummy/test/unit/helpers/repositories_helper_test.rb +4 -0
- data/test/dummy/test/unit/public_key_test.rb +7 -0
- data/test/dummy/test/unit/repository_test.rb +7 -0
- data/test/dummy/test/unit/user_test.rb +7 -0
- data/test/dummy/tmp/cache/assets/C7E/BC0/sprockets%2Fb7118f368364962573a44054bcfb80d0 +0 -0
- data/test/dummy/tmp/cache/assets/C80/840/sprockets%2F562c2d168da585f80579347d10790a0a +0 -0
- data/test/dummy/tmp/cache/assets/C8C/B80/sprockets%2F371bf96e99717688ed7313a0c53f4212 +0 -0
- data/test/dummy/tmp/cache/assets/C9C/700/sprockets%2Fc7b1373dbf219a8722efc21160641340 +0 -0
- data/test/dummy/tmp/cache/assets/C9E/5F0/sprockets%2F2bca2b107bb6c26b720d135270688918 +0 -0
- data/test/dummy/tmp/cache/assets/CA9/9C0/sprockets%2F0c1b7ebd087418498ea6037225d33d25 +0 -0
- data/test/dummy/tmp/cache/assets/CC8/B00/sprockets%2F9815364bfd49ed907870e270d75a995a +0 -0
- data/test/dummy/tmp/cache/assets/CD1/800/sprockets%2Fc044b140dcef533c52712c7b51e21996 +0 -0
- data/test/dummy/tmp/cache/assets/CD5/2C0/sprockets%2F166c056119ebdfb8b7104c97b424b423 +0 -0
- data/test/dummy/tmp/cache/assets/CD7/380/sprockets%2F4079ce1dbbcf4a599527303670006b6b +0 -0
- data/test/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
- data/test/dummy/tmp/cache/assets/CE0/CC0/sprockets%2F2b38c3fb549036de5c4666637a0c80c6 +0 -0
- data/test/dummy/tmp/cache/assets/CEC/B70/sprockets%2F7f98753ca8c35e4249363a04389b3caf +0 -0
- data/test/dummy/tmp/cache/assets/CF0/1D0/sprockets%2F6fc757c2c8329244ca95d6909865bbc2 +0 -0
- data/test/dummy/tmp/cache/assets/CF9/980/sprockets%2Fbd55042e1acd32eb611041444d794d4d +0 -0
- data/test/dummy/tmp/cache/assets/CFD/560/sprockets%2Fe4e7fe4ee089382325686f806b939d3e +0 -0
- data/test/dummy/tmp/cache/assets/D00/B90/sprockets%2F07c00c80f1ea62d95a01f11f9c728b72 +0 -0
- data/test/dummy/tmp/cache/assets/D0D/9A0/sprockets%2F1fce44192cdb30f44b7545a37c9891b2 +0 -0
- data/test/dummy/tmp/cache/assets/D0F/390/sprockets%2F9df081609c3449ab40c93b1cf07de357 +0 -0
- data/test/dummy/tmp/cache/assets/D25/A60/sprockets%2F0e036061ad22b2e6dce1639b234cf15c +0 -0
- data/test/dummy/tmp/cache/assets/D27/DB0/sprockets%2Fa3a0a778855bce9fa47913d389ea9884 +0 -0
- data/test/dummy/tmp/cache/assets/D29/5A0/sprockets%2Fdad9e81b43ca12671246ee52a1900d0c +0 -0
- data/test/dummy/tmp/cache/assets/D2E/FF0/sprockets%2Fc06112642c994b6b7c2ba6632fad1fd0 +0 -0
- data/test/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/test/dummy/tmp/cache/assets/D36/120/sprockets%2Feac54bd3c540af6b964d025e345227d6 +0 -0
- data/test/dummy/tmp/cache/assets/D3E/240/sprockets%2F84b96d6b2d2653cb4127b06d8acb990d +0 -0
- data/test/dummy/tmp/cache/assets/D3F/830/sprockets%2F18578d4ef3abd6e12d836841dd6b8a00 +0 -0
- data/test/dummy/tmp/cache/assets/D4B/E70/sprockets%2F0909bc70e589d40a6cd90dfe6f18257e +0 -0
- data/test/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/test/dummy/tmp/cache/assets/D57/3D0/sprockets%2F7bbccc5129a5013b70831ec9ad62ab24 +0 -0
- data/test/dummy/tmp/cache/assets/D5A/000/sprockets%2F7d4f67f146b6d7904dfc4edd9135f588 +0 -0
- data/test/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/test/dummy/tmp/cache/assets/D5B/BB0/sprockets%2Fba769276c4de14151bc4202cba7f3ad3 +0 -0
- data/test/dummy/tmp/cache/assets/D5E/BC0/sprockets%2F2d96fa667066778db858d7b7cb0fce69 +0 -0
- data/test/dummy/tmp/cache/assets/D6E/BA0/sprockets%2F5178d3788fe35a52acb5f3bd22ea078a +0 -0
- data/test/dummy/tmp/cache/assets/D6F/C20/sprockets%2F22e783a8f5f9224f01e8e62fab6afb40 +0 -0
- data/test/dummy/tmp/cache/assets/D76/5C0/sprockets%2Fd8a5669df31f129f355283e6dab4c5ad +0 -0
- data/test/dummy/tmp/cache/assets/D79/DE0/sprockets%2F7cfd335e68d881b03f6b7f1bd91f270f +0 -0
- data/test/dummy/tmp/cache/assets/D8A/CA0/sprockets%2F656af8b87ad378e8e4f2ec94b6b5c719 +0 -0
- data/test/dummy/tmp/cache/assets/D8C/620/sprockets%2Ff37f8e5b8cccd9880276a9f5157d4c7e +0 -0
- data/test/dummy/tmp/cache/assets/D92/200/sprockets%2Fb816d858281027bdd3fe2bfac43b4ca1 +0 -0
- data/test/dummy/tmp/cache/assets/D92/CE0/sprockets%2Ffca6a13676a2be09234905f9acae22cd +0 -0
- data/test/dummy/tmp/cache/assets/D96/9E0/sprockets%2F6fabecd33f7a5a087f4fb6a2d6312443 +0 -0
- data/test/dummy/tmp/cache/assets/DA2/D20/sprockets%2Ff5faf079fb660bde5bc9502bde442088 +0 -0
- data/test/dummy/tmp/cache/assets/DA5/570/sprockets%2F3517de599b6fd005bc5d5d69ba5ff1e2 +0 -0
- data/test/dummy/tmp/cache/assets/DA7/070/sprockets%2F69eadf8c3a94b04fe0b4992ee4a8c821 +0 -0
- data/test/dummy/tmp/cache/assets/DBA/BF0/sprockets%2Fe63ea1d7bfb0ee50380debe42360a3b5 +0 -0
- data/test/dummy/tmp/cache/assets/DBB/3B0/sprockets%2F6a0aaa6c5b0d10b936e237a7ecb4e4c9 +0 -0
- data/test/dummy/tmp/cache/assets/DBC/8E0/sprockets%2F908976cfbcdf6ad4c59737bf3c78e1e8 +0 -0
- data/test/dummy/tmp/cache/assets/DD3/FD0/sprockets%2Febf97c76a9ba2a889dd01be2caa75806 +0 -0
- data/test/dummy/tmp/cache/assets/DD8/410/sprockets%2Fc02eeb7ea977fd713cc19ca93d838af4 +0 -0
- data/test/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/test/dummy/tmp/cache/assets/DEA/E40/sprockets%2F4166d7d00d1e72fed2004debed2bea3e +0 -0
- data/test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/test/dummy/tmp/cache/assets/E05/C70/sprockets%2Fccd814ec859d582ada46e271edfe7ae1 +0 -0
- data/test/dummy/tmp/cache/assets/E0C/2A0/sprockets%2F37c59fadd9a21cab7d05d78a7dfe7e85 +0 -0
- data/test/dummy/tmp/cache/assets/E28/130/sprockets%2F6f332ca43b7ed658d90b8ba5daaa5ded +0 -0
- data/test/dummy/tmp/cache/assets/E3B/080/sprockets%2F09e2a090befacdae0db10cafb1893a0a +0 -0
- data/test/dummy/tmp/cache/assets/E65/CD0/sprockets%2F93cdf3fec0e3aa6deefa955c6828fbd0 +0 -0
- data/test/dummy/tmp/cache/assets/E9F/450/sprockets%2Fbbfdc5edaaf25dfdb5ee8f9db7895435 +0 -0
- data/test/dummy/tmp/restart.txt +0 -0
- data/test/functional/git_wit/git_controller_test.rb +10 -0
- data/test/git_wit_test.rb +7 -0
- data/test/integration/navigation_test.rb +10 -0
- data/test/test_helper.rb +18 -0
- data/test/unit/auth_test.rb +56 -0
- data/test/unit/authorized_keys_test.rb +57 -0
- data/test/unit/config_test.rb +42 -0
- data/test/unit/shell_test.rb +89 -0
- metadata +409 -0
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
File without changes
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# Configure Rails Environment
|
2
|
+
ENV["RAILS_ENV"] = "test"
|
3
|
+
|
4
|
+
require File.expand_path("../dummy/config/environment.rb", __FILE__)
|
5
|
+
require "rails/test_help"
|
6
|
+
|
7
|
+
Rails.backtrace_cleaner.remove_silencers!
|
8
|
+
|
9
|
+
# Load support files
|
10
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
11
|
+
|
12
|
+
# Load fixtures from the engine
|
13
|
+
if ActiveSupport::TestCase.method_defined?(:fixture_path=)
|
14
|
+
ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
|
15
|
+
end
|
16
|
+
|
17
|
+
require "fileutils"
|
18
|
+
FileUtils.mkdir_p Rails.root.join("tmp").to_s
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class AuthTest < ActiveSupport::TestCase
|
4
|
+
def setup
|
5
|
+
GitWit.stash_config
|
6
|
+
GitWit.default_config!
|
7
|
+
end
|
8
|
+
|
9
|
+
def teardown
|
10
|
+
GitWit.restore_config
|
11
|
+
end
|
12
|
+
|
13
|
+
test "should use username as user model for authentication by default" do
|
14
|
+
assert_equal "example", GitWit.user_for_authentication("example")
|
15
|
+
end
|
16
|
+
|
17
|
+
test "should allow custom user lookups for authentication" do
|
18
|
+
GitWit.config.user_for_authentication = ->(username) { "xxxx" }
|
19
|
+
assert_equal "xxxx", GitWit.user_for_authentication("example")
|
20
|
+
end
|
21
|
+
|
22
|
+
test "should always fail authentication by default" do
|
23
|
+
assert !GitWit.authenticate("example", "password")
|
24
|
+
end
|
25
|
+
|
26
|
+
test "should allow custom user authentication" do
|
27
|
+
GitWit.config.authenticate = ->(user, password) { user == password }
|
28
|
+
assert !GitWit.authenticate("example", "password")
|
29
|
+
assert GitWit.authenticate("example", "example")
|
30
|
+
assert GitWit.authenticate("password", "password")
|
31
|
+
end
|
32
|
+
|
33
|
+
test "should not authorize read by default" do
|
34
|
+
assert !GitWit.authorize_read("example", "test.git")
|
35
|
+
end
|
36
|
+
|
37
|
+
test "should allow custom read authorization" do
|
38
|
+
GitWit.config.authorize_read = ->(user, repository) do
|
39
|
+
repository == "#{user}.git"
|
40
|
+
end
|
41
|
+
assert !GitWit.authorize_read("example", "test.git")
|
42
|
+
assert GitWit.authorize_read("example", "example.git")
|
43
|
+
end
|
44
|
+
|
45
|
+
test "should not authorize write by default" do
|
46
|
+
assert !GitWit.authorize_write("example", "test.git")
|
47
|
+
end
|
48
|
+
|
49
|
+
test "should allow custom write authorization" do
|
50
|
+
GitWit.config.authorize_write = ->(user, repository) do
|
51
|
+
repository == "#{user}.git"
|
52
|
+
end
|
53
|
+
assert !GitWit.authorize_write("example", "test.git")
|
54
|
+
assert GitWit.authorize_write("example", "example.git")
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class AuthorizedKeysTest < ActiveSupport::TestCase
|
4
|
+
def setup
|
5
|
+
GitWit.stash_config
|
6
|
+
GitWit.default_config!
|
7
|
+
GitWit.config.ssh_user = `whoami`.chomp
|
8
|
+
@tmp_keys_path = Rails.root.join("tmp", "authorized_keys").to_s
|
9
|
+
end
|
10
|
+
|
11
|
+
def teardown
|
12
|
+
GitWit.restore_config
|
13
|
+
File.unlink @tmp_keys_path if File.exist? @tmp_keys_path
|
14
|
+
end
|
15
|
+
|
16
|
+
test "should calculate appropriate authorized_keys path for ssh_user" do
|
17
|
+
app_user_keys_path = File.expand_path("~/.ssh/authorized_keys")
|
18
|
+
assert_equal app_user_keys_path, GitWit.authorized_keys_path
|
19
|
+
end
|
20
|
+
|
21
|
+
test "should accept an absolute path for authorized_keys_path in config" do
|
22
|
+
GitWit.config.authorized_keys_path = @tmp_keys_path
|
23
|
+
assert_equal @tmp_keys_path, GitWit.authorized_keys_path
|
24
|
+
end
|
25
|
+
|
26
|
+
test "should generate authorized_keys from key map" do
|
27
|
+
GitWit.config.authorized_keys_path = @tmp_keys_path
|
28
|
+
GitWit.regenerate_authorized_keys(
|
29
|
+
"one" => ["ssh-rsa fakekey1 one@fake1", "ssh-rsa fakekey2 one@fake2"],
|
30
|
+
"two" => ["ssh-rsa fakekey3 two@fake"])
|
31
|
+
key_file = GitWit.authorized_keys_file
|
32
|
+
assert_equal 3, key_file.keys.length
|
33
|
+
assert_equal 2, key_file.keys.map(&:options).map(&:to_s).uniq.length
|
34
|
+
end
|
35
|
+
|
36
|
+
test "should be able to add keys one at a time" do
|
37
|
+
GitWit.config.authorized_keys_path = @tmp_keys_path
|
38
|
+
key_file = GitWit.authorized_keys_file
|
39
|
+
GitWit.add_authorized_key "one", "ssh-rsa fakekey1 one@fake1"
|
40
|
+
assert_equal 1, key_file.keys.length
|
41
|
+
GitWit.add_authorized_key "one", "ssh-rsa fakekey2 one@fake2"
|
42
|
+
assert_equal 2, key_file.keys.length
|
43
|
+
end
|
44
|
+
|
45
|
+
test "should be able to remove keys one at a time" do
|
46
|
+
GitWit.config.authorized_keys_path = @tmp_keys_path
|
47
|
+
GitWit.regenerate_authorized_keys(
|
48
|
+
"one" => ["ssh-rsa fakekey1 one@fake1", "ssh-rsa fakekey2 one@fake2"],
|
49
|
+
"two" => ["ssh-rsa fakekey3 two@fake"])
|
50
|
+
key_file = GitWit.authorized_keys_file
|
51
|
+
assert_equal 3, key_file.keys.length
|
52
|
+
GitWit.remove_authorized_key "ssh-rsa fakekey1 one@fake1"
|
53
|
+
assert_equal 2, key_file.keys.length
|
54
|
+
GitWit.remove_authorized_key "ssh-rsa fakekey2 one@fake2"
|
55
|
+
assert_equal 1, key_file.keys.length
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ConfigTest < ActiveSupport::TestCase
|
4
|
+
def setup
|
5
|
+
GitWit.stash_config
|
6
|
+
GitWit.default_config!
|
7
|
+
end
|
8
|
+
|
9
|
+
def teardown
|
10
|
+
GitWit.restore_config
|
11
|
+
end
|
12
|
+
|
13
|
+
test "should expose a configuration interface" do
|
14
|
+
assert_kind_of Hash, GitWit.config
|
15
|
+
assert !GitWit.config.insecure_write
|
16
|
+
GitWit.configure do |config|
|
17
|
+
config.insecure_write = true
|
18
|
+
end
|
19
|
+
assert GitWit.config.insecure_write
|
20
|
+
end
|
21
|
+
|
22
|
+
test "should empty the config when reset" do
|
23
|
+
GitWit.reset_config!
|
24
|
+
assert !GitWit.config.present?
|
25
|
+
end
|
26
|
+
|
27
|
+
test "should load reasonable config defaults" do
|
28
|
+
assert_kind_of Hash, GitWit.config
|
29
|
+
assert GitWit.config.present?
|
30
|
+
assert_kind_of String, GitWit.config.realm
|
31
|
+
assert_kind_of String, GitWit.config.repositories_path
|
32
|
+
assert !GitWit.config.insecure_write
|
33
|
+
assert !GitWit.config.insecure_auth
|
34
|
+
end
|
35
|
+
|
36
|
+
test "should expose important config parameters directly" do
|
37
|
+
%w(repositories_path ssh_user realm git_http_backend_path
|
38
|
+
insecure_write insecure_auth).each do |p|
|
39
|
+
assert GitWit.respond_to?(p.to_sym)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ShellTest < ActiveSupport::TestCase
|
4
|
+
def setup
|
5
|
+
GitWit.stash_config
|
6
|
+
GitWit.default_config!
|
7
|
+
end
|
8
|
+
|
9
|
+
def teardown
|
10
|
+
GitWit.restore_config
|
11
|
+
end
|
12
|
+
|
13
|
+
test "should use RAILS_ROOT env variable if given" do
|
14
|
+
old_root = ENV.delete "RAILS_ROOT"
|
15
|
+
|
16
|
+
ENV["RAILS_ROOT"] = "/example/rails/app"
|
17
|
+
assert_equal ENV["RAILS_ROOT"], GitWit::Shell.rails_root
|
18
|
+
|
19
|
+
ENV["RAILS_ROOT"] = old_root
|
20
|
+
end
|
21
|
+
|
22
|
+
test "should use BUNDLE_GEMFILE env variable if no rails root" do
|
23
|
+
old_root = ENV.delete "RAILS_ROOT"
|
24
|
+
old_bundle = ENV.delete "BUNDLE_GEMFILE"
|
25
|
+
|
26
|
+
ENV["BUNDLE_GEMFILE"] = "/another/rails/app/Gemfile"
|
27
|
+
assert_equal "/another/rails/app", GitWit::Shell.rails_root
|
28
|
+
|
29
|
+
ENV["RAILS_ROOT"] = old_root
|
30
|
+
ENV["BUNDLE_GEMFILE"] = old_bundle
|
31
|
+
end
|
32
|
+
|
33
|
+
test "should use current directory if no RAILS_ROOT or BUNDLE_GEMFILE given" do
|
34
|
+
old_root = ENV.delete "RAILS_ROOT"
|
35
|
+
old_bundle = ENV.delete "BUNDLE_GEMFILE"
|
36
|
+
|
37
|
+
tmp_dir = Rails.root.join("tmp").to_s
|
38
|
+
assert Dir.exist?(tmp_dir)
|
39
|
+
Dir.chdir(tmp_dir) do
|
40
|
+
assert_equal tmp_dir, GitWit::Shell.rails_root
|
41
|
+
end
|
42
|
+
|
43
|
+
ENV["RAILS_ROOT"] = old_root
|
44
|
+
ENV["BUNDLE_GEMFILE"] = old_bundle
|
45
|
+
end
|
46
|
+
|
47
|
+
test "should deduce the app user from file ownership of rails root" do
|
48
|
+
old_root = ENV.delete "RAILS_ROOT"
|
49
|
+
|
50
|
+
ENV["RAILS_ROOT"] = Rails.root.to_s
|
51
|
+
assert_equal Process.uid, GitWit::Shell.app_user
|
52
|
+
|
53
|
+
ENV["RAILS_ROOT"] = old_root
|
54
|
+
end
|
55
|
+
|
56
|
+
test "should know if it's running as a given user" do
|
57
|
+
assert GitWit::Shell.running_as?(Process.uid)
|
58
|
+
end
|
59
|
+
|
60
|
+
test "should parse git commands into command and repository path" do
|
61
|
+
ENV["SSH_ORIGINAL_COMMAND"] = "#{GitWit::Shell::SHELL_COMMANDS.first} 'example.git'"
|
62
|
+
cmd_repo = GitWit::Shell.parse_ssh_original_command
|
63
|
+
assert_equal 2, cmd_repo.length
|
64
|
+
assert_equal GitWit::Shell::SHELL_COMMANDS.first, cmd_repo.first
|
65
|
+
assert_equal "example.git", cmd_repo.last
|
66
|
+
ENV.delete "SSH_ORIGINAL_COMMAND"
|
67
|
+
end
|
68
|
+
|
69
|
+
test "should authenticate by only confirming that a user exists" do
|
70
|
+
GitWit.config.user_for_authentication = ->(username) { "xxxx" }
|
71
|
+
GitWit.config.authenticate = ->(user, password) { raise "tried auth" }
|
72
|
+
assert_nothing_raised do
|
73
|
+
assert_equal "xxxx", GitWit::Shell.authenticate("example")
|
74
|
+
end
|
75
|
+
GitWit.config.user_for_authentication = ->(username) { nil }
|
76
|
+
assert_nothing_raised do
|
77
|
+
assert_nil GitWit::Shell.authenticate("example")
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
test "should authorize read/write based on git command given" do
|
82
|
+
GitWit.config.authorize_write = ->(user, repository) { user == "w" }
|
83
|
+
GitWit.config.authorize_read = ->(user, repository) { user == "r" }
|
84
|
+
assert GitWit::Shell.authorize("git-receive-pack", "w", "example.git")
|
85
|
+
assert !GitWit::Shell.authorize("git-receive-pack", "r", "example.git")
|
86
|
+
assert !GitWit::Shell.authorize("git-upload-pack", "w", "example.git")
|
87
|
+
assert GitWit::Shell.authorize("git-upload-pack", "r", "example.git")
|
88
|
+
end
|
89
|
+
end
|