ever-co / ever-traduora

Ever® Traduora™ - Open Translation Management Platform - https://traduora.co
https://traduora.co
GNU Affero General Public License v3.0
1.98k stars 198 forks source link

Api endpoints in 0.16 does not work #120

Open arelstone opened 4 years ago

arelstone commented 4 years ago

I can't seem to get any other endpoints then /api/v1/auth/token to work on v. 0.16. I've downgraded to 0.15 this everything seems to work fine.

Could you help me what i'm doing wrong.

In the request headers I'm sending the bearer token and content-type.

The response i get is:

{
    "error": {
        "code": "BadRequest",
        "message": "Your request seems to be invalid or malformed"
    }
}

To Reproduce Steps to reproduce the behavior:

  1. Start the traduora service
  2. Authenticate thru the api with api/v1/auth/token
  3. Request all projects api/v1/projects
  4. See error

Expected behavior I would expect that you would get a list of all projects

Screenshots

Screenshot 2020-04-01 at 07 20 35

Environment (please complete the following information):

Additional context After downgrading to 0.15 the api/v1/projects (and all other endpoints work find and serve me the data as expected

anthonynsimon commented 4 years ago

@arelstone I tried it locally and it seems to work just fine on 0.16.0 (both docker image and building from source).

Could you try to run the end-to-end tests locally? Simply create the database tr_e2e and run bin/test.sh

arelstone commented 4 years ago

@anthonynsimon Some tests failed. Seems like AuthController (e2e) has some issues

 ~/Projects/traduora-test  master ✗                                                                                                                     52m ◒  
▶ ./bin/test.sh
yarn run v1.22.4
$ yarn test && yarn test:e2e
$ cross-env NODE_ENV=test jest
 PASS  src/formatters/android-xml-spec.ts (9.757s)
 PASS  src/formatters/xliff.spec.ts (10.004s)
 PASS  src/formatters/jsonflat.spec.ts (10.447s)
 PASS  src/formatters/jsonnested.spec.ts (10.512s)
 PASS  src/formatters/yaml-nested.spec.ts (10.521s)
 PASS  src/formatters/strings.spec.ts (10.561s)
 PASS  src/formatters/properties.spec.ts (10.659s)
 PASS  src/formatters/csv.spec.ts (10.534s)
 PASS  src/formatters/yaml-flat.spec.ts (10.685s)
 PASS  src/formatters/gettext.spec.ts (10.585s)

Test Suites: 10 passed, 10 total
Tests:       29 passed, 29 total
Snapshots:   0 total
Time:        11.319s
Ran all test suites.
$ cross-env NODE_ENV=e2e TR_DEFAULT_PROJECT_PLAN=default TR_ACCESS_LOGS_ENABLED=false TR_DB_DATABASE=tr_e2e jest --config ./test/jest-e2e.json --runInBand --verbose
 PASS  test/project-label.e2e-spec.ts (46.465s)
  ProjectLabelController (e2e)
    ✓ /api/v1/projects/:projectId/labels (POST) should create labels for project (3484ms)
    ✓ /api/v1/projects/:projectId/labels (POST) should accept labels with utf-8 encoding (2939ms)
    ✓ /api/v1/projects/:projectId/labels (GET) should find labels for project (3198ms)
    ✓ /api/v1/projects/:projectId/labels/:labelId (PATCH) should update a label by id (3177ms)
    ✓ /api/v1/projects/:projectId/labels/:labelId (DELETE) should labels by id (3016ms)
    ✓ /api/v1/projects/:projectId/labels/:labelId/terms/:termId (POST) should label a term (3472ms)
    ✓ should propagate term labels to translations whenever a term, translation or project locale is created (3853ms)
    ✓ /api/v1/projects/:projectId/labels/:labelId/terms/:termId (DELETE) should unlabel a term (3787ms)
    ✓ /api/v1/projects/:projectId/labels/:labelId/terms/:termId/translations/:localeCode (POST) should label a translation (3731ms)
    ✓ /api/v1/projects/:projectId/labels/:labelId/terms/:termId/translations/:localeCode (DELETE) should unlabel a translation (4319ms)
    ✓ /api/v1/projects/:projectId/labels should not access terms resource if not authenticated or authorized (3562ms)

 PASS  test/import.e2e-spec.ts (22.035s)
  ImportController (e2e)
    ✓ /api/v1/projects/:projectId/imports (POST) should automatically create locale for project (4138ms)
    ✓ /api/v1/projects/:projectId/imports (POST) should replace/add translations if locale already exists (3753ms)
    ✓ /api/v1/projects/:projectId/imports (POST) should fail import if would exceed plan limits (3409ms)
    ✓ /api/v1/projects/:projectId/imports (POST) should not import if params are missing or invalid (2993ms)
    ✓ /api/v1/projects/:projectId/imports should not access imports resource if not authenticated (3153ms)
    ✓ /api/v1/projects/:projectId/imports should not access imports resource if not authorized (3380ms)

 PASS  test/translation.e2e-spec.ts (31.782s)
  TranslationController (e2e)
    ✓ /api/v1/projects/:projectId/translations (POST) should create project locale (2853ms)
    ✓ /api/v1/projects/:projectId/translations (POST) should fail if locale already exists for project (3059ms)
    ✓ /api/v1/projects/:projectId/translations (POST) should not create project locale if missing/invalid data or locale not known (2850ms)
    ✓ /api/v1/projects/:projectId/translations (GET) should find project locales (2774ms)
    ✓ /api/v1/projects/:projectId/translations/:localeCode (PATCH) should update translation for existing terms (2671ms)
    ✓ /api/v1/projects/:projectId/translations/:localeCode (PATCH) should accept translations with utf-8 characters (2739ms)
    ✓ /api/v1/projects/:projectId/translations/:localeCode (PATCH) should fail to update translation if term or locale not exists (3047ms)
    ✓ /api/v1/projects/:projectId/translations/:localeCode (GET) should find project translation for locale (3008ms)
    ✓ /api/v1/projects/:projectId/translations/:localeCode (DELETE) should delete project locale (2784ms)
    ✓ /api/v1/projects/:projectId/translations should not access translations resource if not authenticated (2817ms)
    ✓ /api/v1/projects/:projectId/translations should not access translations resource if not authorized (2802ms)

 FAIL  test/auth.e2e-spec.ts (56.364s)
  AuthController (e2e)
    ✓ /api/v1/auth/signup (POST) should signup user (2665ms)
    ✓ /api/v1/auth/signup (POST) should reject signup with invalid email (2702ms)
    ✓ /api/v1/auth/signup (POST) should reject signup with invalid password (2520ms)
    ✓ /api/v1/auth/signup (POST) should reject signup if missing params or malfomed request (2848ms)
    ✓ /api/v1/auth/signup (POST) should reject signup when user already exists (2894ms)
    ✓ /api/v1/auth/token (POST) should grant token to user with valid credentials (5034ms)
    ✕ /api/v1/auth/token (POST) should not grant a token to user with missing credentials (5029ms)
    ✕ /api/v1/auth/token (POST) should grant token to client with valid credentials (4935ms)
    ✓ /api/v1/auth/token (POST) should not grant a token to client with missing credentials (3232ms)
    ✓ /api/v1/auth/token (POST) should not grant token to user with invalid credentials (3184ms)
    ✓ /api/v1/auth/forgot-password (POST) should send forgotten password email to requested user (3195ms)
    ✓ /api/v1/auth/change-password (POST) should change the password if the old one is valid (4104ms)
    ✓ /api/v1/auth/change-password (POST) should not change the password if the old one is invalid (3329ms)
    ✓ /api/v1/auth/change-password (POST) should not change the password if the request is malformed or invalid (3500ms)
    ✓ /api/v1/auth/change-password (POST) should reject the request if the user is not authenticated (3119ms)
    ✓ /api/v1/auth/reset-password (POST) should reset password when token is valid (3633ms)

  ● AuthController (e2e) › /api/v1/auth/token (POST) should not grant a token to user with missing credentials

    Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout.Error: Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout.

      at mapper (../node_modules/jest-jasmine2/build/queueRunner.js:25:45)
          at runMicrotasks (<anonymous>)

  ● AuthController (e2e) › /api/v1/auth/token (POST) should not grant a token to user with missing credentials

    CannotExecuteNotConnectedError: Cannot execute operation on "default" connection because connection is not yet established.

      at new CannotExecuteNotConnectedError (../src/error/CannotExecuteNotConnectedError.ts:8:9)
      at Connection.<anonymous> (../src/connection/Connection.ts:223:19)
      at step (../node_modules/tslib/tslib.js:136:27)
      at Object.next (../node_modules/tslib/tslib.js:117:57)
      at ../node_modules/tslib/tslib.js:110:75
      at Object.__awaiter (../node_modules/tslib/tslib.js:106:16)
      at Connection.Object.<anonymous>.Connection.close (../node_modules/typeorm/connection/Connection.js:168:24)
      at Object.<anonymous> (auth.e2e-spec.ts:456:31)

  ● AuthController (e2e) › /api/v1/auth/token (POST) should grant token to client with valid credentials

    QueryFailedError: ER_CANNOT_ADD_FOREIGN: Cannot add foreign key constraint

      at new QueryFailedError (../src/error/QueryFailedError.ts:9:9)
      at Query.<anonymous> (../src/driver/mysql/MysqlQueryRunner.ts:166:37)
      at Query.<anonymous> (../node_modules/mysql/lib/Connection.js:525:10)
      at Query._callback (../node_modules/mysql/lib/Connection.js:491:16)
      at Query.Object.<anonymous>.Sequence.end (../node_modules/mysql/lib/protocol/sequences/Sequence.js:83:24)
      at Query.Object.<anonymous>.Query.ErrorPacket (../node_modules/mysql/lib/protocol/sequences/Query.js:90:8)
      at Protocol.Object.<anonymous>.Protocol._parsePacket (../node_modules/mysql/lib/protocol/Protocol.js:291:23)
      at Parser._parsePacket (../node_modules/mysql/lib/protocol/Parser.js:433:10)
      at Parser.write (../node_modules/mysql/lib/protocol/Parser.js:43:10)
      at Protocol.Object.<anonymous>.Protocol.write (../node_modules/mysql/lib/protocol/Protocol.js:38:16)

  ● AuthController (e2e) › /api/v1/auth/token (POST) should grant token to client with valid credentials

    QueryFailedError: ER_TABLE_EXISTS_ERROR: Table 'label_terms_term' already exists

      at new QueryFailedError (../src/error/QueryFailedError.ts:9:9)
      at Query.<anonymous> (../src/driver/mysql/MysqlQueryRunner.ts:166:37)
      at Query.<anonymous> (../node_modules/mysql/lib/Connection.js:525:10)
      at Query._callback (../node_modules/mysql/lib/Connection.js:491:16)
      at Query.Object.<anonymous>.Sequence.end (../node_modules/mysql/lib/protocol/sequences/Sequence.js:83:24)
      at Query.Object.<anonymous>.Query.ErrorPacket (../node_modules/mysql/lib/protocol/sequences/Query.js:90:8)
      at Protocol.Object.<anonymous>.Protocol._parsePacket (../node_modules/mysql/lib/protocol/Protocol.js:291:23)
      at Parser._parsePacket (../node_modules/mysql/lib/protocol/Parser.js:433:10)
      at Parser.write (../node_modules/mysql/lib/protocol/Parser.js:43:10)
      at Protocol.Object.<anonymous>.Protocol.write (../node_modules/mysql/lib/protocol/Protocol.js:38:16)

  ● AuthController (e2e) › /api/v1/auth/token (POST) should grant token to client with valid credentials

    TypeError: Cannot read property 'id' of undefined

      51 |     });
      52 |   const result = res.body.data as TestingProject;
    > 53 |   if (!result.id || !result.name || !result.role) {
         |               ^
      54 |     throw new Error('Malformed create project response! Maybe fields need updating?');
      55 |   }
      56 |   return result;

      at Object.<anonymous> (util.ts:53:15)
      at fulfilled (util.ts:4:58)
          at runMicrotasks (<anonymous>)

  ● AuthController (e2e) › /api/v1/auth/token (POST) should grant token to client with valid credentials

    CannotExecuteNotConnectedError: Cannot execute operation on "default" connection because connection is not yet established.

      at new CannotExecuteNotConnectedError (../src/error/CannotExecuteNotConnectedError.ts:8:9)
      at Connection.<anonymous> (../src/connection/Connection.ts:223:19)
      at step (../node_modules/tslib/tslib.js:136:27)
      at Object.next (../node_modules/tslib/tslib.js:117:57)
      at ../node_modules/tslib/tslib.js:110:75
      at Object.__awaiter (../node_modules/tslib/tslib.js:106:16)
      at Connection.Object.<anonymous>.Connection.close (../node_modules/typeorm/connection/Connection.js:168:24)
      at Object.<anonymous> (auth.e2e-spec.ts:456:31)

 PASS  test/project-client.e2e-spec.ts (36.829s)
  ProjectClientController (e2e)
    ✓ /api/v1/projects/:projectId/clients (GET) should return all project clients (4040ms)
    ✓ /api/v1/projects/:projectId/clients (POST) should create a project clients, and be able to authenticate with the secret given (3884ms)
    ✓ /api/v1/projects/:projectId/clients (POST) should not create a project client if the request is malformed (3752ms)
    ✓ /api/v1/projects/:projectId/clients/:clientId (PATCH) should be able to edit project clients if allowed (3710ms)
    ✓ /api/v1/projects/:projectId/clients/:clientId (DELETE) should remove project clients if allowed (3874ms)
    ✓ a project client should be able to access endpoints according to its role (3878ms)
    ✓ a project client should not be able to access non-project specific endpoints (3470ms)
    ✓ a project client should not be able to access a project which is not his own (3321ms)
    ✓ /api/v1/projects/:projectId/clients should not access project clients resource if not authenticated (3268ms)
    ✓ /api/v1/projects/:projectId/clients should not access project clients resource if not authorized (3140ms)

 PASS  test/project.e2e-spec.ts (47.591s)
  ProjectController (e2e)
    ✓ /api/v1/projects (POST) should create a project and assign the user as admin (3057ms)
    ✓ /api/v1/projects (POST) should accept projects with utf-8 characters in the name or description (3567ms)
    ✓ /api/v1/projects (POST) should not create a project if missing params or malformed request (2949ms)
    ✓ /api/v1/projects (GET) should return projects for which requesting user has access to (2868ms)
    ✓ /api/v1/projects (GET) should not return projects for which requesting user has no access (3143ms)
    ✓ /api/v1/projects/:projectId (GET) should find a project by id (3277ms)
    ✓ /api/v1/projects/:projectId (GET) should not find a project by id if user has no access (3426ms)
    ✓ /api/v1/projects (POST) should not create a project if the user has created too many (8043ms)
    ✓ /api/v1/projects/:projectId (PATCH) should update a project (3754ms)
    ✓ /api/v1/projects/:projectId (PATCH) should not update a project if user has no access (3329ms)
    ✓ /api/v1/projects/:projectId (DELETE) should not delete a project by id if user has no access (3279ms)
    ✓ /api/v1/projects/:projectId (DELETE) should delete a project by id (2900ms)
    ✓ /api/v1/projects should not access projects resource if not authenticated (2961ms)

 PASS  test/export.e2e-spec.ts (26.976s)
  ExportController (e2e)
    ✓ /api/v1/projects/:projectId/exports?format=jsonflat (GET) should export project translation in JSON flat format (3199ms)
    ✓ /api/v1/projects/:projectId/exports (GET) should export terms in lexical order (3455ms)
    ✓ /api/v1/projects/:projectId/exports (GET) should export translation with utf-8 characters in various formats (3398ms)
    ✓ /api/v1/projects/:projectId/exports?format=jsonflat (GET) should include empty translations on export (3242ms)
    ✓ /api/v1/projects/:projectId/exports?format=jsonflat (GET) should not export if params are missing or invalid (3372ms)
    ✓ /api/v1/projects/:projectId/exports?format=jsonflat (GET) should not export if locale does not exist for project (3271ms)
    ✓ /api/v1/projects/:projectId/exports should not access exports resource if not authenticated (3481ms)
    ✓ /api/v1/projects/:projectId/exports should not access exports resource if not authorized (3203ms)

 PASS  test/project-user.e2e-spec.ts (20.444s)
  ProjectUserController (e2e)
    ✓ /api/v1/projects/:projectId/users (GET) should return all project users including self (2856ms)
    ✓ /api/v1/projects/:projectId/users/:userId (PATCH) should be able to edit project users if allowed (2763ms)
    ✓ /api/v1/projects/:projectId/users/:userId (PATCH) should not affect the other projects from that user (2914ms)
    ✓ /api/v1/projects/:projectId/users/:userId (PATCH) should not be able to edit or remove yourself (2954ms)
    ✓ /api/v1/projects/:projectId/users/:userId (DELETE) should remove project users if allowed (2873ms)
    ✓ /api/v1/projects/:projectId/users should not access project users resource if not authenticated (2931ms)
    ✓ /api/v1/projects/:projectId/users should not access project users resource if not authorized (2806ms)

 PASS  test/user.e2e-spec.ts (12.914s)
  UserController (e2e)
    ✓ /api/v1/users/me (GET) should return requesting user info (2698ms)
    ✓ /api/v1/users/me (PATCH) should update a users name or email (2589ms)
    ✓ /api/v1/users/me (PATCH) should reject a malformed name or email on update (2453ms)
    ✓ /api/v1/users/me (DELETE) should not delete a users account if he is last project user and project has a team (2433ms)
    ✓ /api/v1/users/me (DELETE) should delete a users account, but keep the projects and related resources unaffected (2385ms)

 PASS  test/project-plan.e2e-spec.ts
  PlansController (e2e)
    ✓ /v1/projects/:projectId/plan (GET) should return the current project plan (14ms)
    ✓ adding terms should count towards the project plan (57ms)
    ✓ removing terms should count towards the project plan (54ms)
    ✓ adding locales should count towards the project plan (58ms)
    ✓ removing locales should count towards the project plan (51ms)
    ✓ should not be able to add terms if would exceed current plan quota (897ms)
    ✓ should not be able to add locales if would exceed current plan quota (433ms)
    ✓ /v1/projects/:projectId/plan should not access plan resource if not authenticated (2ms)
    ✓ /v1/projects/:projectId/plan should not access plan resource if not authorized (9ms)

 PASS  test/term.e2e-spec.ts (17.21s)
  TermController (e2e)
    ✓ /api/v1/projects/:projectId/terms (POST) should create terms for project (2015ms)
    ✓ /api/v1/projects/:projectId/terms (GET) should find terms for project (2029ms)
    ✓ /api/v1/projects/:projectId/terms (GET) should return terms in lexical order (2273ms)
    ✓ /api/v1/projects/:projectId/terms/:termId (PATCH) should update term by id (2125ms)
    ✓ /api/v1/projects/:projectId/terms/:termId (PATCH) should accept terms with utf-8 encoding (2122ms)
    ✓ /api/v1/projects/:projectId/terms/:termId (DELETE) should delete term by id (2189ms)
    ✓ /api/v1/projects/:projectId/terms should not access terms resource if not authenticated (2048ms)
    ✓ /api/v1/projects/:projectId/terms should not access terms resource if not authorized (2138ms)

 PASS  test/project-stats.e2e-spec.ts (6.844s)
  ProjectStatsController (e2e)
    ✓ /api/v1/projects/:projectId/stats (GET) should get the project locale stats (2529ms)
    ✓ /api/v1/projects/:projectId/translations should not access stats resource if not authenticated (2058ms)
    ✓ /api/v1/projects/:projectId/translations should not access stats resource if not authorized (1969ms)

 PASS  test/project-invite.e2e-spec.ts (10.847s)
  ProjectInviteController (e2e)
    ✓ /api/v1/projects/:projectId/invites (GET) should return all project invites including self (2166ms)
    ✓ /api/v1/projects/:projectId/invites (POST) with a new user should create a new invite (1959ms)
    ✓ /api/v1/projects/:projectId/invites (POST) with an existing user should create a new project user (2114ms)
    ✓ /api/v1/projects/:projectId/invites/:inviteId (PATCH) should update the role of the invite (2041ms)
    ✓ /api/v1/projects/:projectId/invites/:inviteId (DELETE) should delete the invite (2234ms)

 PASS  test/locale.e2e-spec.ts
  LocaleController (e2e)
    ✓ /api/v1/locales (GET) should return locales (36ms)

 PASS  test/health.e2e-spec.ts
  HealthController (e2e)
    ✓ /health (GET) (5ms)

Test Suites: 1 failed, 14 passed, 15 total
Tests:       2 failed, 112 passed, 114 total
Snapshots:   0 total
Time:        344.595s
Ran all test suites.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

I've noticed that if i boot up the 0.15 i get this reponse witch seems odd, because I would suppose that it was version 0.15 but it gives me 0.16. Don't know if this has something to say, but i think it's odd

{
  "status": "ok",
  "version": "0.16.0"
}

Steps:

  1. Stop docker image that I just cloned (0.16)
  2. cd into the dir with 0.15
  3. docker-compose up
  4. Navigate to http://loclahost:8080/health
anthonynsimon commented 4 years ago

@arelstone Thanks for the detailed info. Do you know which version of MySQL are you using?

arelstone commented 4 years ago

I ran the tests thru the docker image so the one the image uses

anthonynsimon commented 4 years ago

@arelstone do you still have this issue? Unfortunately I still wasn't able to reproduce it :/

arelstone commented 4 years ago

@anthonynsimon Im not sure, as mentioned earlier i downgraded to 0.15 and this seems to be working