@@ -84,3 +84,62 @@ def test_repository_not_found(self):
84
84
}
85
85
}))
86
86
self .assertEqual (reply .status_code , 404 )
87
+
88
+ @patch ('jens.webapps.gitlabproducer.enqueue_hint' )
89
+ def test_secret_token_ignored_if_not_configured (self , mock_eq ):
90
+ self .settings .GITLAB_PRODUCER_SECRET_TOKEN = None
91
+ _payload = {
92
+ 'repository' : {
93
+ 'name' : 'it-puppet-site' ,
94
+ 'git_ssh_url' : "file://%s" % self .site_bare
95
+ }
96
+ }
97
+ reply = self .app .post ('/gitlab' ,
98
+ content_type = 'application/json' ,
99
+ headers = {'X-Gitlab-Token' : 'tokenvalue' },
100
+ data = json .dumps (_payload ))
101
+ mock_eq .assert_called_once_with ('common' , 'site' )
102
+ self .assertEqual (reply .status_code , 200 )
103
+
104
+ def test_wrong_secret_token (self ):
105
+ self .settings .GITLAB_PRODUCER_SECRET_TOKEN = 'expected'
106
+ _payload = {
107
+ 'repository' : {
108
+ 'name' : 'it-puppet-site' ,
109
+ 'git_ssh_url' : "file://%s" % self .site_bare
110
+ }
111
+ }
112
+ reply = self .app .post ('/gitlab' ,
113
+ content_type = 'application/json' ,
114
+ data = json .dumps (_payload ))
115
+ self .assertEqual (reply .status_code , 401 )
116
+
117
+ def test_secret_token_configured_wrong_token (self ):
118
+ self .settings .GITLAB_PRODUCER_SECRET_TOKEN = 'expected'
119
+ _payload = {
120
+ 'repository' : {
121
+ 'name' : 'it-puppet-site' ,
122
+ 'git_ssh_url' : "file://%s" % self .site_bare
123
+ }
124
+ }
125
+ reply = self .app .post ('/gitlab' ,
126
+ content_type = 'application/json' ,
127
+ headers = {'X-Gitlab-Token' : 'tokenvalue' },
128
+ data = json .dumps (_payload ))
129
+ self .assertEqual (reply .status_code , 401 )
130
+
131
+ @patch ('jens.webapps.gitlabproducer.enqueue_hint' )
132
+ def test_secret_token_configured_good_token (self , mock_eq ):
133
+ self .settings .GITLAB_PRODUCER_SECRET_TOKEN = 'expected'
134
+ _payload = {
135
+ 'repository' : {
136
+ 'name' : 'it-puppet-site' ,
137
+ 'git_ssh_url' : "file://%s" % self .site_bare
138
+ }
139
+ }
140
+ reply = self .app .post ('/gitlab' ,
141
+ content_type = 'application/json' ,
142
+ headers = {'X-Gitlab-Token' : 'expected' },
143
+ data = json .dumps (_payload ))
144
+ mock_eq .assert_called_once_with ('common' , 'site' )
145
+ self .assertEqual (reply .status_code , 200 )
0 commit comments