3.3 - Laboratoire 3


Linky

Programmer un gestionnaire d'URL raccourcies accessible via HTTP. Utiliser ce client en ligne de commande comme point de départ.

  • La manipulation des utilisateurs est fournie dans ce fichier, on simule la gestion des utilisateurs via un tableau en mémoire
    • Toutes les routes demandent une authentification et concernent les données de l'utilisateur connecté, sauf /l/... qui permet de naviguer vers une URL
  • Le serveur respecte la structure REST
    • Vous devez sauvegarder les liens dans un fichier en vous assurant d'identifier l'utilisateur créateur du lien
    • La liste retourne seulement les données de l'utilisateur authentifié
    • À l'ajout d'un lien, valider les données reçues, que l'URL est réellement accessible et générer un hash alphanumérique aléatoire de 6 charactères
      • On peut également modifier l'URL d'un hash existant
      • L'ajout et la modification peuvent recevoir le contenu en JSON ou en texte brute. Assurez-vous de démontrer que votre serveur supporte les 2 formats.
    • Le suppression valide que l'item existe avant de supprimer
    • La navigation permets de partager une URL courte qui redirigera vers la destination enregistrée précédemment, si le hash précisé existe
    • Effectuer les validations pertinentes pour encadrer les données reçues par le serveur

Serveur

Liste

GET /links
Authorization: Basic ...

===

200
Content-Type: application/json
[
  { "url": ..., "hash": ... }
  ...
]

~~~ Authentification invalide

401
Content-Type: text/plain
WWW-Authenticate: Basic

Ajout

POST /links
Authorization: Basic ...
Content-Type: application/json | text/plain

{ "url": ... }  | ...url...

===

201
Content-Type: application/json
{ "url": ..., "hash": ... }

~~~

400
Content-Type: text/plain
...Error Message...

~~~ Authentification invalide

401
Content-Type: text/plain
WWW-Authenticate: Basic

Modification

PATCH /links/...HASH...
Authorization: Basic ...
Content-Type: application/json | text/plain

{ "url": ... }  | ...URL...

===

200
Content-Type: application/json
{ "url": ..., "hash": ... }

~~~

404
Content-Type: text/plain
Link not found

~~~

400
Content-Type: text/plain
...Error Message...

~~~ Authentification invalide

401
Content-Type: text/plain
WWW-Authenticate: Basic

Suppression

DELETE /links/...HASH...
Authorization: Basic ...

===

204
Content-Type: text/plain

~~~

404
Content-Type: text/plain
Link not found

~~~ Authentification invalide

401
Content-Type: text/plain
WWW-Authenticate: Basic

Navigation

GET /l/...HASH...

===

307 
Content-Type: text/plain
Location: ...URL...

~~~

404
Content-Type: text/plain
Link not found

Client

Authentification

Username: abcde
Password: wrong  

~~~~~~   LINKY   ~~~~~~
l: List  a: Add  e: Edit  d: Delete  q: Quit
>> l

~~~~~~   LINKY   ~~~~~~
Invalid credentials

Press Enter to continue...

Username: alice
Password: pwda

Liste

~~~~~~   LINKY   ~~~~~~
l: List  a: Add  e: Edit  d: Delete  q: Quit
>> l     

~~~~~~   LINKY   ~~~~~~
http://localhost:4567/l/AYk95N
 ↪  http://shawinigan.info
http://localhost:4567/l/4mxExA
 ↪  http://cshaw.jhoffman.ca

Press Enter to continue...

Ajout

~~~~~~   LINKY   ~~~~~~
l: List  a: Add  e: Edit  d: Delete  q: Quit
>> a

~~~~~~   LINKY   ~~~~~~
URL: patate
Invalid URL, host unreachable

Press Enter to continue...

~~~~~~   LINKY   ~~~~~~
l: List  a: Add  e: Edit  d: Delete  q: Quit
>> a

~~~~~~   LINKY   ~~~~~~
URL: http://perdu.com

New link added: http://localhost:4567/l/oWF6HP

Press Enter to continue...

Modification

~~~~~~   LINKY   ~~~~~~
l: List  a: Add  e: Edit  d: Delete  q: Quit
>> e

~~~~~~   LINKY   ~~~~~~
Hash: patate
URL: http://perdu.com

Link not found

Press Enter to continue...

~~~~~~   LINKY   ~~~~~~
l: List  a: Add  e: Edit  d: Delete  q: Quit
>> e

~~~~~~   LINKY   ~~~~~~
Hash: a3Xrth
URL: http://perdu.com

Link updated
http://localhost:4567/l/a3Xrth
 ↪  http://perdu.com

Press Enter to continue...

Suppression

~~~~~~   LINKY   ~~~~~~
l: List  a: Add  e: Edit  d: Delete  q: Quit
>> l

~~~~~~   LINKY   ~~~~~~
http://localhost:4567/l/AYk95N
 ↪  http://shawinigan.info
http://localhost:4567/l/4mxExA
 ↪  http://cshaw.jhoffman.ca
http://localhost:4567/l/oWF6HP
 ↪  http://perdu.com

Press Enter to continue...

~~~~~~   LINKY   ~~~~~~
l: List  a: Add  e: Edit  d: Delete  q: Quit
>> d

~~~~~~   LINKY   ~~~~~~
Hash: patate
Link not found

Press Enter to continue...

~~~~~~   LINKY   ~~~~~~
l: List  a: Add  e: Edit  d: Delete  q: Quit
>> d

~~~~~~   LINKY   ~~~~~~
Hash: AYk95N 

Press Enter to continue...

Quitter

~~~~~~   LINKY   ~~~~~~
l: List  a: Add  e: Edit  d: Delete  q: Quit
>> q

Remise

17 novembre, 8h AM via LÉA

  • Envoyer uniquement vos fichiers Ruby nommés server.rb et client.rb
  • Inscrire votre nom en commentaire sur la première ligne

Critères d’évaluation

Laboratoire 3 - 5% / 26

Nom: ____________________________________

Qualité de rédaction: Nomenclature, Formatage, Syntaxe, Réutilisation 0 -0.5 -1 -1.5 -2
Serveur
GET /links: auth = status, headers, body, fichier 0 0.5 1 1.5 2
POST /links: auth, headers, body = status, headers, body, validations, fichier 0 0.5 1 1.5 2
PATCH /links/...HASH...: auth, headers, body = status, headers, body, validations, fichier 0 0.5 1 1.5 2
DELETE /links/...HASH...: auth = status, headers, body, validations, fichier 0 0.5 1 1.5 2
GET /l/...HASH... = status, headers, body, validations, fichier 0 0.5 1 1.5 2
Gestion du fichier, intégration du module d'authentification 0 0.5 1 1.5 2
Client
Authentification 0 0.5 1 1.5 2
Liste: requête, réponse, affichage 0 0.5 1 1.5 2
Ajout: requête, réponse, affichage 0 0.5 1 1.5 2
Modification: requête, réponse, affichage 0 0.5 1 1.5 2
Modification/Ajout: Format du body json ou texte 0 1 2
Suppression: requête, réponse, affichage 0 0.5 1 1.5 2
Intégration au client fourni, UI/UX cohérent 0 0.5 1 1.5 2