def test_verify_invalid(self): with assert_raises(HookError): utils.verify_hook_signature( self.node_settings, HOOK_PAYLOAD, {'X-Hub-Signature': 'invalid'} )
def test_verify_valid(self): try: utils.verify_hook_signature( self.node_settings, HOOK_PAYLOAD, { 'X-Hub-Signature': make_signature( self.node_settings.hook_secret, HOOK_PAYLOAD, ) }) except HookError: assert 0
def test_verify_valid(self): try: utils.verify_hook_signature( self.node_settings, HOOK_PAYLOAD, { 'X-Hub-Signature': make_signature( self.node_settings.hook_secret, HOOK_PAYLOAD, ) } ) except HookError: assert 0
def gitlab_hook_callback(node_addon, **kwargs): """Add logs for commits from outside OSF. """ if request.json is None: return {} # Fail if hook signature is invalid verify_hook_signature( node_addon, request.data, request.headers, ) node = kwargs['node'] or kwargs['project'] payload = request.json for commit in payload.get('commits', []): # TODO: Look up OSF user by commit # Skip if pushed by OSF if commit['message'] and commit['message'] in MESSAGES.values(): continue _id = commit['id'] date = dateparse(commit['timestamp']) committer = commit['committer']['name'] # Add logs for path in commit.get('added', []): add_hook_log( node, node_addon, 'gitlab_' + NodeLog.FILE_ADDED, path, date, committer, include_urls=True, sha=_id, ) for path in commit.get('modified', []): add_hook_log( node, node_addon, 'gitlab_' + NodeLog.FILE_UPDATED, path, date, committer, include_urls=True, sha=_id, ) for path in commit.get('removed', []): add_hook_log( node, node_addon, 'gitlab_' + NodeLog.FILE_REMOVED, path, date, committer, ) node.save()
def gitlab_hook_callback(node_addon, **kwargs): """Add logs for commits from outside OSF. """ if request.json is None: return {} # Fail if hook signature is invalid verify_hook_signature( node_addon, request.data, request.headers, ) node = kwargs['node'] or kwargs['project'] payload = request.json for commit in payload.get('commits', []): # TODO: Look up OSF user by commit # Skip if pushed by OSF if commit['message'] and commit['message'] in MESSAGES.values(): continue _id = commit['id'] date = dateparse(commit['timestamp']) committer = commit['committer']['name'] # Add logs for path in commit.get('added', []): add_hook_log( node, node_addon, 'gitlab_' + NodeLog.FILE_ADDED, path, date, committer, include_urls=True, sha=_id, ) for path in commit.get('modified', []): add_hook_log( node, node_addon, 'gitlab_' + NodeLog.FILE_UPDATED, path, date, committer, include_urls=True, sha=_id, ) for path in commit.get('removed', []): add_hook_log( node, node_addon, 'gitlab_' + NodeLog.FILE_REMOVED, path, date, committer, ) node.save()
def test_verify_no_secret(self): self.node_settings.hook_secret = None with assert_raises(HookError): utils.verify_hook_signature(self.node_settings, {}, {})
def test_verify_invalid(self): with assert_raises(HookError): utils.verify_hook_signature(self.node_settings, HOOK_PAYLOAD, {'X-Hub-Signature': 'invalid'})
def test_verify_no_secret(self): self.node_settings.hook_secret = None with assert_raises(HookError): utils.verify_hook_signature(self.node_settings, {}, {})