Skip to content

Commit

Permalink
[CAT-1270] Fix bug in sync lib script (#97)
Browse files Browse the repository at this point in the history
* Partially rollback change to sync-lib.sh
* Run Rufus linter against python webhook event verifier
  • Loading branch information
dvacca-onfido authored Jul 1, 2024
1 parent 12ce23f commit 01ed1b5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
11 changes: 7 additions & 4 deletions generators/python/urllib3/templates/webhook_event_verifier.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
import hmac
import hashlib
import json

from .models import WebhookEvent


class OnfidoInvalidSignatureError(Exception):
pass


class WebhookEventVerifier:
def __init__(self, webhook_token):
self.webhook_token = webhook_token

def read_payload(self, raw_event, signature):
# Compute the the actual HMAC signature from the raw request body.
event_signature = hmac.new(key=self.webhook_token.encode("utf-8"),
msg=raw_event.encode("utf-8"),
digestmod=hashlib.sha256).hexdigest()
event_signature = hmac.new(
key=self.webhook_token.encode("utf-8"),
msg=raw_event.encode("utf-8"),
digestmod=hashlib.sha256,
).hexdigest()

# Compare the signatures (prevent against timing attacks).
if not hmac.compare_digest(signature, event_signature):
Expand Down
14 changes: 7 additions & 7 deletions shell/sync-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ fi

if [[ "$OSTYPE" = "darwin"* ]]; then
# Mac OSX
SED=(sed -i -E)
SED_OPTS="-i -E"
else
# Linux
SED=(sed -i)
SED_OPTS="-i"
fi

# Sync library contents
Expand All @@ -39,29 +39,29 @@ rsync -r --exclude='/.git*' --exclude='/CHANGELOG*' --exclude='/.release.json' \
case $client_lib_name in

java)
$SED 's/ *$//' pom.xml
sed $SED_OPTS 's/ *$//' pom.xml
mvn -B package --file pom.xml clean -Dmaven.test.skip
;;

node)
# workaround typeMappings setting not working with typescript-node generator
$SED 's/\([ <{]\)File\([>},]\)/\1FileTransfer\2/g' api.ts
sed $SED_OPTS 's/\([ <{]\)File\([>},]\)/\1FileTransfer\2/g' api.ts
npx prettier --write package.json
npm install
;;

php)
$SED "s/ *$//" composer.json
sed $SED_OPTS "s/ *$//" composer.json
composer update --lock
;;

python)
$SED "s/ *$//" pyproject.toml setup.py
sed $SED_OPTS "s/ *$//" pyproject.toml setup.py
pipx run poetry==1.8 lock
;;

ruby)
$SED "s/ *$//" Gemfile
sed $SED_OPTS "s/ *$//" Gemfile
bundle lock --update
;;

Expand Down

0 comments on commit 01ed1b5

Please sign in to comment.