profcfuhrmanets / log210-systeme-gestion-bordereau-node-express-ts

Système de gestion des bordereaux (SGB) utilisé dans le cadre du cours de LOG210.
https://profcfuhrmanets.github.io/log210-systeme-gestion-bordereau-node-express-ts/
0 stars 17 forks source link

API request for `api/v3/teachers/login` and `api/v3/students/login` fails #27

Closed Cryotechnic closed 2 months ago

Cryotechnic commented 2 months ago

French version will follow/La version française suivra

The GET requests on both API endpoints above fail because the server does not handle body/json and body/form-data responses in the selector in the API documentation.

A theory that my professor (Patrice Robitaille) and I theorized is that it had something to do with how the server handles errors when the username/password is invalid.

This is a potential cause for concern as it makes it impossible to successfully authenticate the user, thus making the F2 case (in the FURPS) section automatically fail because the criteria are not fulfilled.


Les requêtes GET sur les deux endpoints de l'API ci-dessus échouent parce que le serveur ne gère pas les réponses body/json et body/form-data dans le sélecteur de la documentation de l'API.

Mon professeur (Patrice Robitaille) et moi-même avons théorisé que cela avait quelque chose à voir avec la façon dont le serveur gère les erreurs lorsque le nom d'utilisateur/mot de passe n'est pas valide.

Il s'agit d'une cause potentielle de préoccupation car il est impossible d'authentifier avec succès l'utilisateur, ce qui fait que le cas F2 (dans la section FURPS) échoue automatiquement parce que les critères ne sont pas respectés.

Cryotechnic commented 2 months ago

Update 11bcd2115b0200306f02bb720adeeeabdaa233a8

As of the commit above, the API documentation was changed to apidoc. That being said, executing any endpoint will lead to the following error: Error: Cannot find module '../data/{file}.json', with {file} changing depending on the type of content that should be retrieved.

Here's the full stacktrace:

Error: Cannot find module '../data/courses.json'
Require stack:
- C:\Users\cryog\OneDrive\Documents\GitHub Repos\log210-systeme-gestion-bordereau-node-express-ts\dist\model\Course.js
- C:\Users\cryog\OneDrive\Documents\GitHub Repos\log210-systeme-gestion-bordereau-node-express-ts\dist\controller\CourseController.js
- C:\Users\cryog\OneDrive\Documents\GitHub Repos\log210-systeme-gestion-bordereau-node-express-ts\dist\routes\CourseRouter.js
- C:\Users\cryog\OneDrive\Documents\GitHub Repos\log210-systeme-gestion-bordereau-node-express-ts\dist\App.js
- C:\Users\cryog\OneDrive\Documents\GitHub Repos\log210-systeme-gestion-bordereau-node-express-ts\dist\index.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1144:15)
    at Module._load (node:internal/modules/cjs/loader:985:27)
    at Module.require (node:internal/modules/cjs/loader:1235:19)
    at require (node:internal/modules/helpers:176:18)
    at Course.all (C:\Users\cryog\OneDrive\Documents\GitHub Repos\log210-systeme-gestion-bordereau-node-express-ts\dist\model\Course.js:8:23)
    at CourseController.all (C:\Users\cryog\OneDrive\Documents\GitHub Repos\log210-systeme-gestion-bordereau-node-express-ts\dist\controller\CourseController.js:13:32)
    at CourseRouter.all (C:\Users\cryog\OneDrive\Documents\GitHub Repos\log210-systeme-gestion-bordereau-node-express-ts\dist\routes\CourseRouter.js:20:36)
    at Layer.handle [as handle_request] (C:\Users\cryog\OneDrive\Documents\GitHub Repos\log210-systeme-gestion-bordereau-node-express-ts\node_modules\.pnpm\express@4.19.2\node_modules\express\lib\router\layer.js:95:5)
    at next (C:\Users\cryog\OneDrive\Documents\GitHub Repos\log210-systeme-gestion-bordereau-node-express-ts\node_modules\.pnpm\express@4.19.2\node_modules\express\lib\router\route.js:149:13)
    at Route.dispatch (C:\Users\cryog\OneDrive\Documents\GitHub Repos\log210-systeme-gestion-bordereau-node-express-ts\node_modules\.pnpm\express@4.19.2\node_modules\express\lib\router\route.js:119:3)
Olon11 commented 2 months ago

C'est probablement relié à #28, car les fichiers ne sont pas transférés dans le répertoire.

Olon11 commented 2 months ago

Peux-tu vérifier que les changements dans la branche feature/improve-docs règlent ce problème?

fuhrmanator commented 2 months ago

@Cryotechnic je me demande si ce n'est pas ce changement ce n'est pas ce changement qui cause le problème: https://github.com/profcfuhrmanets/log210-systeme-gestion-bordereau-node-express-ts/blob/dde5bd32fca84d05a792d8b5850f28cdcfd31945/src/App.ts#L30-L32

Peux-tu mettre ces lignes en commentaires est essayer à court terme?

fuhrmanator commented 2 months ago

Voici un exemple pour reproduire l'erreur:

fetch('http://localhost:3200/api/v3/courses/all')
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error('Error:', error));
fuhrmanator commented 2 months ago

Voici une solution à court terme. Avant de rouler le serveur, il faut copier les données:

cp -r src/data dist/data

On va faire une corrective aujourd'hui - j'ai une assemblée départementale à midi.

fuhrmanator commented 2 months ago

Un autre exemple pour valider:

import md5 from "md5";

console.log('Fetch teachers from the server');
const teacherId: string = 'teacher+3@gmail.com';

fetch('http://localhost:3200/api/v3/teacher/all', {
    headers: {
        'Authorization': 'Bearer ' + md5(teacherId) 
    }
})
    .then(response => response.json())
    .then(data => console.log(data))
    .catch(error => console.error('Error:', error));
Olon11 commented 2 months ago

Voici une solution à court terme. Avant de rouler le serveur, il faut copier les données:

C'est ce que je crois. J'ai ajouté le correctif dans ma PR. Il reste à tester.

Olon11 commented 2 months ago

J'ai testé et je n'ai pas le problème sur Windows avec les changements que j'ai faits dans #31