Skip to content

Commit

Permalink
Refactor, add tests, update README
Browse files Browse the repository at this point in the history
  • Loading branch information
adeveloper-wq committed Jun 18, 2024
1 parent 360b3c4 commit d1b88ae
Show file tree
Hide file tree
Showing 7 changed files with 714 additions and 100 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.21.x'

- name: Test
run: go test -v ./...

- name: Log in to the container registry
uses: docker/login-action@v2
with:
Expand Down
30 changes: 27 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,39 @@
# PrioBike Shlink Guard

This is a proxy that can be used in front of the Shlink to make sure that only valid requests and espacially valid long links are sent to the Shlink.

## Quickstart

Run locally:
```bash
docker-compose up
```

Run tests:
```bash
curl -X POST --header "X-Api-Key: secret" -H "Content-Type: application/json" -d @example_long_link.json http://localhost/rest/v3/short-urls
go test
```

Then
### POST

Should not work:
```bash
curl -X POST --header "X-Api-Key: secret" -H "Content-Type: application/json" -d @example_long_link_base64_invalid.json http://localhost/rest/v3/short-urls
```

Should work:
```bash
curl -X GET --header "X-Api-Key: secret" -H "Content-Type: application/json" -d @example_long_link.json http://localhost/rest/v3/short-urls/<shortcode>
curl -X POST --header "X-Api-Key: secret" -H "Content-Type: application/json" -d @example_long_link_shortcut_location.json http://localhost/rest/v3/short-urls
```

### GET

Should not work:
```bash
curl -X GET --header "X-Api-Key: secret" -H "Content-Type: application/json" http://localhost/rest/v3/short-urls
```

Should work (if short link exists):
```bash
curl -X GET --header "X-Api-Key: secret" -H "Content-Type: application/json" http://localhost/rest/v3/short-urls/segrs4
```
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ services:
environment:
# Http cannot be omitted here
- PROXY_TARGET=http://shlink:8080
- LOGGING_LEVEL=debug
- LOG_LEVEL=debug
networks:
- test-network
labels:
Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module shlink-guard

go 1.21.3
Loading

0 comments on commit d1b88ae

Please sign in to comment.