SciCatProject / SciCatProject/backend

Testing access of specific users to the instances by ID

Open
#1,778 0 comments 0 reactions 1 assignee View on GitHub

@sofyalaski is already working on this.

Since Mar 20, 2025.

testing
Dominant language
TypeScript
Stars
27
Forks
37
Avg merge
17h 32m
Merged PRs (30d)
38

Description

Summary

While testing GET endpoints we have many tests that just compare the number of instances a user should get but not check them by ID. Changing that by also specifying the IDs would make changing tests, avoid mess (especially adding new ones) easier and explicitly check access to correct instances.

Current Behaviour

An example from current master in test/DatasetAuthorization.js:

  it("0100: list of datasets for Admin Ingestor", async () => {
    return request(appUrl)
      .get("/api/v3/Datasets")
      .set("Accept", "application/json")
      .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` })
      .expect(TestData.SuccessfulGetStatusCode)
      .expect("Content-Type", /json/)
      .then((res) => {
        res.body.should.be.an("array").to.have.lengthOf(3);
      });
  });

This type of test that checks for the length of a response array appears for both v3 and v4 APIs and for datasets, jobs, samples etc.

Expected Behaviour

When these instances get created with post endpoints, assign Ids to them ( done anyway for some of them), reuse them especially in case of complex authorization rules to not only check the array size but also presence of certain Ids:

it("0350: Access jobs as user5", async () => {
    return request(appUrl)
      .get(`/api/v3/Jobs/`)
      .send({})
      .set("Accept", "application/json")
      .set({ Authorization: `Bearer ${accessTokenUser51}` })
      .expect(TestData.SuccessfulGetStatusCode)
      .expect("Content-Type", /json/)
      .then((res) => {
        res.body.should.be.an("array").to.have.lengthOf(2);
        res.body.map(job => job.id).should.include.members([jobId4, jobId5]);
      });
  });

Details

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.