Commit 062ace4a authored by Guilhem Saurel's avatar Guilhem Saurel
Browse files

gh: client → async_client

parent a1e22e2a
Pipeline #15351 failed with stage
in 32 seconds
......@@ -126,12 +126,12 @@ class GhTests(TestCase):
signature = 'sha1=' + hmac.new(force_bytes(settings.GITHUB_WEBHOOK_KEY), msg, digestmod=sha1).hexdigest()
LOGGER.info('posting a simulated gh webhook event')
LOGGER.debug(f'with: {data}')
return await self.client.post(reverse('webhook'),
data,
content_type='application/json',
X_FORWARDED_FOR='140.82.112.1',
X_HUB_SIGNATURE=signature,
X_GITHUB_EVENT=event)
return await self.async_client.post(reverse('webhook'),
data,
content_type='application/json',
X_FORWARDED_FOR='140.82.112.1',
X_HUB_SIGNATURE=signature,
X_GITHUB_EVENT=event)
@redact_token
async def gl_webhook_event(self, event, last_commit='', branch='master', status=''):
......@@ -154,34 +154,34 @@ class GhTests(TestCase):
}
}
gl_webhook = reverse('gl-webhook')
return await self.client.post(gl_webhook,
data,
content_type='application/json',
X_FORWARDED_FOR='140.93.0.1',
X_GITLAB_TOKEN=settings.GITLAB_WEBHOOK_KEY,
X_GITLAB_EVENT=event)
return await self.async_client.post(gl_webhook,
data,
content_type='application/json',
X_FORWARDED_FOR='140.93.0.1',
X_GITLAB_TOKEN=settings.GITLAB_WEBHOOK_KEY,
X_GITLAB_EVENT=event)
async def test_gh_webhook(self):
"""Test the security of the github webhook."""
# Not from github IP
response = await self.client.get(reverse('webhook'), X_FORWARDED_FOR='5.5.5.5')
response = await self.async_client.get(reverse('webhook'), X_FORWARDED_FOR='5.5.5.5')
self.assertEqual(response.status_code, 302)
# No signature
response = await self.client.get(reverse('webhook'), X_FORWARDED_FOR='140.82.112.1')
response = await self.async_client.get(reverse('webhook'), X_FORWARDED_FOR='140.82.112.1')
self.assertEqual(response.status_code, 302)
# Signature not sha1
response = await self.client.get(reverse('webhook'),
X_FORWARDED_FOR='140.82.112.1',
X_HUB_SIGNATURE='sha256=foo')
response = await self.async_client.get(reverse('webhook'),
X_FORWARDED_FOR='140.82.112.1',
X_HUB_SIGNATURE='sha256=foo')
self.assertEqual(response.status_code, 501)
# Wrong signature
response = await self.client.get(reverse('webhook'),
X_FORWARDED_FOR='140.82.112.1',
X_HUB_SIGNATURE='sha1=foo')
response = await self.async_client.get(reverse('webhook'),
X_FORWARDED_FOR='140.82.112.1',
X_HUB_SIGNATURE='sha1=foo')
self.assertEqual(response.status_code, 403)
# Ping
......@@ -193,22 +193,22 @@ class GhTests(TestCase):
# Not from gitlab IP
gl_webhook = reverse('gl-webhook')
response = await self.client.get(gl_webhook, X_FORWARDED_FOR='5.5.5.5')
response = await self.async_client.get(gl_webhook, X_FORWARDED_FOR='5.5.5.5')
self.assertEqual(response.status_code, 302)
# No token
response = await self.client.get(gl_webhook, X_FORWARDED_FOR='140.93.0.1')
response = await self.async_client.get(gl_webhook, X_FORWARDED_FOR='140.93.0.1')
self.assertEqual(response.status_code, 302)
# Wrong token
response = await self.client.get(gl_webhook, X_FORWARDED_FOR='140.93.0.1', X_GITLAB_TOKEN='foo')
response = await self.async_client.get(gl_webhook, X_FORWARDED_FOR='140.93.0.1', X_GITLAB_TOKEN='foo')
self.assertEqual(response.status_code, 403)
# Ping
response = await self.client.get(gl_webhook,
X_FORWARDED_FOR='140.93.0.1',
X_GITLAB_TOKEN=settings.GITLAB_WEBHOOK_KEY,
X_GITLAB_EVENT='ping')
response = await self.async_client.get(gl_webhook,
X_FORWARDED_FOR='140.93.0.1',
X_GITLAB_TOKEN=settings.GITLAB_WEBHOOK_KEY,
X_GITLAB_EVENT='ping')
self.assertEqual(response.status_code, 200)
async def test_push_already_synced(self):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment