summaryrefslogtreecommitdiff
path: root/testing
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2017-07-08 15:43:56 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2017-07-08 15:43:56 +0100
commitc3b09524a73fd362d5ac1c2080639ad95b0456b2 (patch)
tree57007f01b492c490574119ccd95efff1788d1fdf /testing
parent5d81846da0d3f827235e2fdd209541e005dfafb7 (diff)
parentaedd1964a467e4f9aaca49ca5fa2bb40a81e1ca8 (diff)
downloadgitano-c3b09524a73fd362d5ac1c2080639ad95b0456b2.tar.gz
Merge branch 'dsilvers/hooks'
Diffstat (limited to 'testing')
-rw-r--r--testing/01-hooks.yarn73
-rw-r--r--testing/gitano-test-tool.in34
-rw-r--r--testing/library.yarn6
3 files changed, 112 insertions, 1 deletions
diff --git a/testing/01-hooks.yarn b/testing/01-hooks.yarn
new file mode 100644
index 0000000..b3e4413
--- /dev/null
+++ b/testing/01-hooks.yarn
@@ -0,0 +1,73 @@
+<!-- -*- markdown -*- -->
+Basic hook support tests
+========================
+
+In these tests we verify the various hooks function at some basic level.
+
+For example, we check that we can abort some of the hooks and that we can
+alter behaviour or add behaviour to certain hooks which might commonly be
+used for the sorts of things plugins want.
+
+Preauthorization commandline hook
+---------------------------------
+
+The preauth_cmdline hook is used to allow plugins to adjust (or reject) the
+parsed command line before Gitano even looks up what command it might be for.
+This could be used to add aliases for certain commands, or just stop things
+from happening...
+
+ SCENARIO preauth_cmdline can be manipulated
+ GIVEN a standard instance
+
+ WHEN testinstance adminkey runs ls
+ THEN stdout contains gitano-admin
+
+ GIVEN HOOK_ABORT is in the environment set to PREAUTH_CMDLINE
+
+ WHEN testinstance adminkey, expecting failure, runs ls
+ THEN stderr contains Aborted on request
+
+ GIVEN HOOK_ABORT is not in the environment
+ AND HOOK_DECLINE is in the environment set to PREAUTH_CMDLINE
+
+ WHEN testinstance adminkey, expecting failure, runs ls
+ THEN stderr contains Declined on request
+
+ GIVEN HOOK_DECLINE is not in the environment
+ AND PREAUTH_CMDLINE_REMOVEME is in the environment set to 1
+
+ WHEN testinstance adminkey runs removeme ls
+ THEN stdout contains gitano-admin
+
+ GIVEN PREAUTH_CMDLINE_REMOVEME is not in the environment
+
+ WHEN testinstance adminkey, expecting failure, runs removeme ls
+ THEN stderr contains removeme
+
+ FINALLY the instance is torn down
+
+Post Receieve hook
+------------------
+
+The `POST_RECEIVE` hook allows plugins to perform actions during post-receive.
+This is after the commits have made it into the repository, and after the refs
+have been updated. The `POST_RECEIVE` hook gets given the set of updates which
+were applied to the repository and it gets to take action. Generally we don't
+recommend that hooks _stop_ the chain, but they can, which lets us do things
+like preventing Supple running.
+
+ SCENARIO supple isn't even considered when post_receive hooks "stop"
+ ASSUMING gitano is being accessed over ssh
+
+ GIVEN a standard instance
+ AND testinstance using adminkey has patched gitano-admin with post-receive-alert.patch
+ AND HOOK_DECLINE is in the environment set to POST_RECEIVE
+ WHEN testinstance using adminkey clones gitano-admin.git as gitano-admin
+ AND testinstance using adminkey pushes an empty commit in gitano-admin
+ WHEN testinstance using bypasskey pushes an empty commit in gitano-admin
+ THEN the output does not contain PERIL
+ AND the output does not contain CRITICAL FAILURE
+ AND the output does not contain XYZZY
+ AND the output contains HOOKFUNC_STOPPED
+
+ FINALLY the instance is torn down
diff --git a/testing/gitano-test-tool.in b/testing/gitano-test-tool.in
index f467918..1fd39b0 100644
--- a/testing/gitano-test-tool.in
+++ b/testing/gitano-test-tool.in
@@ -70,10 +70,28 @@ local function unix_assert(ret, errno)
end
end
+local function load_env(into)
+ local f, msg = loadfile(basedir .. ".gtt-env")
+ if f then
+ setfenv(f, into)
+ f()
+ end
+end
+
+local function save_env(env)
+ local f = io.open(basedir .. ".gtt-env", "w")
+ for k, v in pairs(env) do
+ f:write(("%s = %q\n"):format(k, v))
+ end
+ f:close()
+end
+
local function run_program(t)
- if t.env and os.getenv("GITANO_DUMP_VARIABLE_FILE") then
+ t.env = (t.env or {})
+ if os.getenv("GITANO_DUMP_VARIABLE_FILE") then
t.env["GITANO_DUMP_VARIABLE_FILE"] = os.getenv("GITANO_DUMP_VARIABLE_FILE")
end
+ load_env(t.env)
local f = io.open(basedir .. "last-program", "w")
local function print (...)
f:write(...)
@@ -180,6 +198,20 @@ function cmd_setgitconfig(username, key, value)
}
end
+function cmd_setenv(key, value)
+ local t = {}
+ load_env(t)
+ t[key] = value
+ save_env(t)
+end
+
+function cmd_unsetenv(key)
+ local t = {}
+ load_env(t)
+ t[key] = nil
+ save_env(t)
+end
+
function cmd_createunixuser(username)
assert(sio.mkdir(user_home(username), "0755"))
assert(sio.mkdir(ssh_base(username), "0755"))
diff --git a/testing/library.yarn b/testing/library.yarn
index 6facf2a..a370bfe 100644
--- a/testing/library.yarn
+++ b/testing/library.yarn
@@ -283,6 +283,12 @@ Generic utility methods
IMPLEMENTS ASSUMING gitano is being accessed over ([^ ]+)
test "$GTT_PROTO" = "$MATCH_1"
+ IMPLEMENTS GIVEN ([^ ]+) is in the environment set to (.+)
+ $GTT setenv "$MATCH_1" "$MATCH_2"
+
+ IMPLEMENTS GIVEN ([^ ]+) is not in the environment
+ $GTT unsetenv "$MATCH_1"
+
GPG Keyring related helpers
---------------------------