Skip to content

Commit

Permalink
update the necessary documentation files and remove unused use statem…
Browse files Browse the repository at this point in the history
…ent from test
  • Loading branch information
patrick-blom committed Sep 24, 2019
1 parent 918e7fa commit 3e6d9fe
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 3 deletions.
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
## [0.0.4] - 2019-09-24
### Added
- Add the possibility to delete a created short link
### Changed
- Introduce the new token
- Edit the UriManager and Tests
- Edit the UriController and Tests
- Edit the README.md
- Finally use the CHANGELOG.md file

## [0.0.3] - 2019-09-02
### Added
- Add a favicon
- Add the apache package for symfony
### Changed
- Update the readme file to announce the mod_apache package

## [0.0.2] - 2019-08-31
### Changed
- Applied merge requests to simplify the UriController,
the UriManager and fix some phpdocs

## [0.0.1] - 2019-06-23 (first release)
### Added
- Add the possibility to create short links
- Add the possibility to use short links
36 changes: 34 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ To get Shorty up'n running follow these simple steps:
- clone the repository
- run composer install`
- change the `PUT_TOKEN` inside the .env file to something you prefer
- change the `DELETE_TOKEN` inside the .env file to something you prefer
- run `php bin/console doctrine:database:create` to create the database
- run `php bin/console doctrine:migrations:migrate --no-interaction ` to setup the schema
- navigate to /public and run the local PHP Server with `php -S 127.0.0.1:8000`
Expand All @@ -59,13 +60,13 @@ you that Shorty is going out to have a cup of tea if there is some free time.
### Create a short link
If you want that Shorty creates a short link for you, you have to send
him a PUT request. The following example will show you how it works with
curl from a mac.
curl in the terminal.

```
curl -X PUT -H 'Authorization: 5449f071773861dca4d3b459aa79fcf5' -d 'https://github.com/patrick-blom/shorty' http://127.0.0.1:8000
```
```
-X PUT: tell curl to send a PUT request
-X PUT: Tell curl to send a PUT request
-H 'Authorization: 5449f071773861dca4d3b459aa79fcf5': The token you provide under .env PUT_TOKEN (5449f071773861dca4d3b459aa79fcf5)
-d 'https://github.com/patrick-blom/shorty': The Url you want to short (must be a syntactical valid url)
http://127.0.0.1:8000: Your running Shorty
Expand All @@ -86,6 +87,37 @@ Shorty will now take the identifier and search for it in his database.
If he finds a result he will pass a 301 HTTP Response including the
original url back to the browser.

### Delete a short link
Sometimes it happens that you pass something to Shorty you want to delete
later. This can happen for several reasons. One reason could be that there is a typo
in your very long url and you don't want to mess up the database. Another one
could be, that you only want to share the short link for a limited amount of time.
Never mind, there can always be a reason for the deletion of a short link. So if
you want to delete a short link you have to send Shorty a DELETE request with the
created short code. If we take the example from above, it would look like this.

```
curl -X DELETE -H 'Authorization: 5449f071773861dca4d3b459aa79fcf5' -d '950a0065' http://127.0.0.1:8000
```
```
-X DELETE: Tell curl to send a DELETE request
-H 'Authorization: 5449f071773861dca4d3b459aa79fcf5': The token you provide under .env DELETE_TOKEN (5449f071773861dca4d3b459aa79fcf5)
-d '950a0065': The short code which was created by Shorty during the PUT request
http://127.0.0.1:8000: Your running Shorty
```

If everything works as expected, Shorty will return a 410 HTTP Gone Response.
Otherwise you will end up with an 400 HTTP Bad Request Response.

### Security
Shorty's defense is really simple. The only thing between the world and the database
are your authorization tokens. So please keep the following recommendations in mind

- choose long and complex tokens
- never share your tokens
- never use the same token for PUT and DELETE
- always use HTTPS, if you can

## Testing
If you want to test Shorty you can this by simply run a regular
`composer install` and `composer test` in the project root. This will
Expand Down
1 change: 0 additions & 1 deletion tests/Unit/Factory/DeleteUriRequestFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use App\Exception\RequestDoesNotContainAValidShortyHashException;
use App\Factory\DeleteUriRequestFactory;
use App\Factory\PutUriRequestFactory;
use App\Struct\DeleteUriRequest;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
Expand Down

0 comments on commit 3e6d9fe

Please sign in to comment.