Skip to content

Commit

Permalink
Merge pull request #5 from GrantBirki/touch-ups
Browse files Browse the repository at this point in the history
cleanup unused scripts
  • Loading branch information
GrantBirki authored Oct 17, 2024
2 parents dac62e1 + 055d05b commit 24378db
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 100 deletions.
15 changes: 0 additions & 15 deletions script/all

This file was deleted.

71 changes: 0 additions & 71 deletions script/deploy

This file was deleted.

3 changes: 0 additions & 3 deletions script/format
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
set -e

source script/setup-env $@

echo -e "🧹 ${BLUE}formatting ${PURPLE}crystal${BLUE} files...${OFF}"

crystal tool format $@

echo -e "${GREEN}formatting complete!${OFF}"
3 changes: 0 additions & 3 deletions script/lint
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
set -e

source script/setup-env $@

echo -e "🖌️ ${BLUE}linting ${PURPLE}crystal${BLUE} files..."

"$DIR/bin/ameba" $@

echo -e "${GREEN}linting complete!${OFF}"
1 change: 0 additions & 1 deletion script/preinstall
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
set -e

source script/setup-env $@

mkdir -p "$DIR/bin"
7 changes: 0 additions & 7 deletions script/server

This file was deleted.

19 changes: 19 additions & 0 deletions script/test_with_coverage
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,25 @@ fi

crystal build "$DIR/script/require_spec.cr" -D skip-integration -o "$DIR/bin/require_spec" --exclude-warnings $SHARDS_INSTALL_PATH

if [ -d "$DIR/coverage" ]; then
rm -rf "$DIR/coverage"
fi

mkdir -p "$DIR/coverage"

$KCOV_BIN --clean --include-path=$DIR/src "$DIR/coverage" "$DIR/bin/require_spec"

coverage=0

# grep index.js for "covered":"100.0" to check if all files have 100% coverage
if grep -q '"covered":"100.0"' "$DIR/coverage/index.js"; then
echo -e "${GREEN}All files have 100% coverage!${OFF}"
coverage=0
else
echo -e "${RED}Some files do not have 100% coverage!${OFF}"
coverage=1
fi

CRYSTAL_OPTS="" crystal tool unreachable "$DIR/script/require_spec.cr" --check

exit $coverage
27 changes: 27 additions & 0 deletions spec/kemal-hmac/kemal-hmac_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,33 @@ describe "Kemal::Hmac" do
context.kemal_authorized_client?.should eq(client)
end

it "fails when multiple of the required HMAC headers are an empty string" do
client = "valid-octo-client"
hmac_handler = SpecAuthHandler.new(
hmac_secrets: {client => ["octo-secret-blue", "octo-secret-green"]},
)

hmac_client = Kemal::Hmac::Client.new(client, "octo-secret-green", "SHA256")
headers = hmac_client.generate_headers("/api")

request = HTTP::Request.new(
"GET",
"/api",
headers: HTTP::Headers{
"hmac-client" => headers["hmac-client"],
"hmac-timestamp" => "",
"hmac-token" => "",
},
)

io, context = create_request_and_return_io_and_context(hmac_handler, request)
response = HTTP::Client::Response.from_io(io, decompress: false)
response.status_code.should eq 401
response.body.should contain "Unauthorized: empty required hmac headers"
context.kemal_authorized_client?.should eq(nil)
context.response.headers["empty-hmac-headers"].should eq "hmac-timestamp,hmac-token"
end

it "rejects the request when the HMAC token does not match exactly" do
client = "valid-octo-client"
hmac_handler = SpecAuthHandler.new(
Expand Down

0 comments on commit 24378db

Please sign in to comment.