summaryrefslogtreecommitdiff
path: root/testing/01-hooks.yarn
blob: b29841779dfd5121c664b0e224ad7ff5ddf77377 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<!-- -*- 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
    ASSUMING gitano is being accessed over ssh
    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