QA Interview Hub · Knowledge base · Quizzes · Українська

QA Fundamentals

Manual API testing

REST, Postman, Swagger

What is a REST API and what do you check in API testing?

REST is an architectural style: resources have addresses, actions are HTTP methods and the server keeps no state between requests. A 200 does not mean the API works, so a request is checked in layers: status, headers, body against the schema, system state (a follow-up GET or the database) and negative cases. An API test is faster and more stable than a UI test but cannot see rendering.

QA Fundamentals · Manual API testing

The endpoint answered 200. Does that mean the API works?

A tester sends a POST for a transfer, sees 200 and a green tick in Postman. The next day accounting finds a mismatch: the money was debited but the transfer does not exist in the system. The status code only said the server answered without an error, not that the right thing was done. This lesson is about what a REST API is, how API testing differs from testing through the interface and which layers a check of a single request consists of.

How it works and why. REST (Representational State Transfer) is an architectural style described by Roy Fielding: a set of constraints, not a protocol. In practice "REST API" almost always means an HTTP API with JSON. Each constraint gives the tester a concrete thing to check:

  • Resources at addresses. Entities (/transfers, /transfers/t-501) have stable URLs. A test checks the collection, a single resource and nested paths.
  • A uniform interface. An action is expressed by an HTTP method (GET reads, POST creates, PUT and PATCH change, DELETE removes) and the result by a status code. If an endpoint GET /deleteUser?id=5 changes data, the interface is broken, and that is a risk (a prefetch or a crawler can call it).
  • No state between requests. The server does not remember the previous request: the token, the language and the parameters arrive in every one. So requests can run in any order, and a dependency between tests appears only through data in the system (create, then read).
  • Representations. A resource is returned as JSON or another format described by the Content-Type header. The client and the server must understand field types, the date format and the amount format in the same way.

An API test works below the interface: it sends a request directly and sees what the browser hides (headers, exact types, every error code). It is faster and more stable than a UI test, and it finds bugs earlier, when there is no screen yet. The price is that it cannot check the display or usability.

The layers of checking one request

1. Status code201 Created, not "something successful"2. HeadersContent-Type, Location, cache, CORS3. Bodyfields, types, values, error format4. System stateGET after POST, a DB row, side effects5. Non-functionalresponse time, security, limits
Figure 1. A check does not end at the status code. The highlighted layer is the one most often skipped.

Example: from "200, so it is fine" to five checks. The tester sent a request and looked only at the status:

POST /api/transfers HTTP/1.1
Authorization: Bearer <token>
Content-Type: application/json

{"from": "acc-1", "to": "acc-2", "amount": 100.50, "currency": "UAH"}

HTTP/1.1 200 OK
Content-Type: application/json

{"id": "t-501", "amount": "100.5", "currency": "UAH", "status": "done"}

Status 200 means "success", so the test is "green". Now go through the layers. The first three are visible in the response itself, the rest need a second request and the database:

1. Status:   expected 201 Created (per the spec), got 200
2. Headers:  no Location with the path of the new resource
3. Body:     amount must be the number 100.50, a string "100.5" came back
             status must be "pending" per the contract, "done" came back
4. State:    GET /api/transfers/t-501 → 404 (the record was not created)
             no row in transfers and no entries in ledger in the DB
5. Negative: the same with amount = -5, without a token, with a foreign account

How to read it. The first three points are found from the response: creating a resource is expected to be 201 with a Location header (RFC 9110), and the type of the amount field deviates from the contract. The fourth point is impossible without a second request: only a GET after the POST or a database query shows that the record did not appear and there are no ledger entries. The fifth (negative cases) checks that the system refuses where it should. The same failure can show up on several layers, so start with the cheapest (status and body) and move on to the system state.

Limits and alternatives. The word "REST" is used in three senses, and it helps to tell them apart in an interview. Strict REST includes hypertext links (HATEOAS), but most public "REST" APIs have none and are really HTTP APIs with resource addresses. There are RPC-style APIs (POST /transfers/create) and they are tested with the same layers, only without the expectation that the method carries semantics. Other approaches have their own check points: GraphQL has a single endpoint and errors often arrive in the body with status 200; gRPC works with typed messages over HTTP/2, and Postman or curl are less convenient there. An API test does not replace a UI test: it will not show that a button is covered or an amount is displayed wrongly. And it does not see what the client does with the response.

Common mistakes.

  • Checking only the status code: a body with wrong types or values passes unnoticed, and another service finds the mismatch later in production.
  • Not checking the state after changes: a 201 with no record in the system is a serious bug that a status-only test will not see.
  • Testing only the happy path: the most interesting defects live in invalid data, missing fields, foreign IDs and a missing token.
  • Relying on the order of requests between tests: a test that works only after another one breaks in a parallel run. Each test prepares its own data.
  • Treating "REST" and "JSON" as the same thing: the format does not guarantee that actions match the HTTP methods.

Check yourself

POST /orders returns 201 and a correct body, but a customer complains the order is not visible in the list. Which two layers of checking have you not covered yet and how do you cover them?

Answer

The system state layer. Make GET /orders/{id} and GET /orders (is the record in the collection, do the fields match) and, if needed, check the DB row and side effects (an event, a queue, an email). Also the headers layer: the list may be cached (Cache-Control, ETag), and the new record appears with a delay.

Why is the answer "status 200, but the body has {"error": "…"}" a problem for API testing?

Answer

Because status codes exist so that clients and intermediaries (load balancers, caches, monitoring) can tell success from failure without reading the body. When the error hides under 200, monitoring says "all good" and a status check passes. The exception is GraphQL, where execution errors usually arrive in the errors field with status 200 (a request that fails to parse or validate gets 4xx under the GraphQL over HTTP spec with graphql-response+json), so that field is what you check there.

In an interview. Junior: REST is a style where resources have addresses and actions are performed by HTTP methods. I check the status code, the body (fields, types, values), headers, negative cases with invalid data and without authorisation, and that the change really happened, through a following GET or in the database. Middle/Senior: For each request I go through layers: status, headers, body against the schema, system state, non-functional properties. I watch state and side effects especially, because the defects invisible from the status live there. I keep tests independent, prepare data inside the test and log deviations from the specification as separate bugs. API checks complement UI tests rather than replace them: they are faster and more stable but do not see the display.

How do you work in Postman?

In Postman, requests are grouped into collections and whatever changes between runs (environment address, token, IDs) moves into variables. Pre-request scripts prepare data; Post-response scripts write assertions and save values for later requests. Nothing is hard-coded, and assertions describe the contract, not just the status. Secrets stay out of the shared value (formerly initial value), which syncs to the cloud, and go to the local value or Vault.

QA Fundamentals · Manual API testing

A 40-request collection works for you and is red on CI. What went wrong?

A colleague sends a Postman collection and everything is red for you: requests go to someone else's environment, the token is expired, request 12 has an empty ID that was "supposed to remain" from request 11. Each cause is easy to fix separately, but together they show that the collection was built as a set of separate requests, not as a test. This lesson is about what working in Postman consists of, how variables and scripts work there and what turns a collection from a notebook into a repeatable test.

How it works and why. Postman keeps requests in collections (with folders) and moves whatever changes between runs into variables: the environment address, the token, the ID of a created resource. Variables exist in several scopes, and on a name clash the narrower one wins: local over data, data over environment, environment over collection, collection over global. Thanks to this a collection does not depend on the environment: {{baseUrl}} is taken from the selected environment, and switching dev to staging changes one place instead of forty requests.

Variable scope and precedence

Locallives only within one request runDataa CSV/JSON row in Collection RunnerEnvironmentdev / staging: baseUrl, tokenCollectionshared by all requests in the collectionGlobalvisible everywhere, lowest precedence
Figure 1. If a variable with the same name exists in several scopes, the one higher in the diagram is used.

Two things people often mix up. First, a variable has a shared value (formerly initial value; synced to the cloud and visible to those you share the collection with) and a local value (formerly current value; stays local). Secrets such as a token are kept in the local value, and better still in a secret variable type or a vault. Second, scripts come in two kinds: the Scripts tab has Pre-request (runs before sending: prepare data, compute a signature) and Post-response (after the response: assertions, saving values). The latter used to be called the Tests tab. Scripts can be attached to a collection or a folder, and then they run for every request inside (the collection first, then the folder, then the request itself).

Example: from a notebook collection to a chain. Before: every request has the full address and the token written in, and there is a single check, "status is not 4xx"; the ID of a resource for the next request was copied by hand. After: the address is in {{baseUrl}}, authorisation (Bearer {{token}}) is configured once at the collection level, and the requests are linked by variables:

A chain of requests in a collection

1. Login2. Create transfer3. Get transfer4. Delete transfer→ token← token, → transferId← transferId← transferId
Figure 2. Each request reads the variables of the previous ones and writes its own. Data is prepared inside the collection, not by hand.

The script in the "Create transfer" request turns it from "sent and looked" into a check:

// Scripts → Post-response of the "Create transfer" request
pm.test('201 Created', () => pm.response.to.have.status(201));

const ct = pm.response.headers.get('Content-Type');
pm.test('JSON', () => pm.expect(ct).to.include('application/json'));

const body = pm.response.json();
pm.test('amount is stored', () => pm.expect(body.amount).to.eql(100.5));
pm.test('fast enough', () => pm.expect(pm.response.responseTime).to.be.below(800));

// for the next requests: GET /transfers/{{transferId}}
pm.collectionVariables.set('transferId', body.id);

What matters here. The assertions describe the contract (status, content type, value), not "something came back". The response time is compared with a threshold that has a justification (an SLO), and 800 is only an example. Saving transferId makes the next requests independent of a human: Get and Delete take the ID from the variable. The Login request puts the token into the environment, and the collection on CI gets it the same way, without copying. For a table of input values (different amounts and currencies) use Collection Runner with a CSV or JSON file: each row is one iteration, and the values are available as data variables.

Limits and alternatives. Postman is good for exploring an API, manual checks and quick regression sets, but it has limits. A collection is a big JSON that compares poorly in code review, and scripts live in a sandbox with a limited set of libraries. For CI Postman recommends Postman CLI; Newman is still found in existing pipelines, but new ones should take the CLI. When there are many tests, they need complex data or code shared with the rest of the automation, teams move to code in a repository: Playwright or REST Assured. Postman then stays for exploration and reproducing bugs. Secrets are a separate matter: a collection that is exported or published must not contain real tokens and passwords in the shared value.

Common mistakes.

  • Hard-coding the address and the token in requests: the collection is tied to one environment, and the token expires and ends up in an export.
  • Asserting only the status: the test does not see wrong values and types in the body.
  • Depending on manual copying of IDs between requests: the collection cannot be re-run, nor run on CI.
  • Keeping secrets in the shared value: they sync to the cloud and become visible to those you share the collection with.
  • Creating data and not cleaning up: after twenty runs the environment holds hundreds of "test" records. Add a DELETE at the end of the chain.
  • Mixing up variable scope: a local value "overrides" the environment, and the request goes somewhere unexpected.

Check yourself

The Login request puts the token into the variable token, yet Create transfer still answers 401. Name two causes related to variables.

Answer

The variable was written in one scope (say, collection), while the request reads another one with the same name that has higher precedence (an environment with a stale token). Or the token did not reach the Authorization header (the request has No Auth set or does not inherit the collection authorisation), or the variable is named differently (letter case in the name matters).

Why use Collection Runner with a data file instead of copying a request ten times?

Answer

One request with different inputs is a table-driven test: each row of CSV or JSON gives an iteration with its own variables. Changes are made in one place, new cases are added as a row in the file, and the report shows exactly which iteration failed.

In an interview. Junior: In Postman I keep requests in collections, move addresses and tokens into environment variables, prepare data in pre-request scripts, and in post-response scripts (formerly the Tests tab) I write checks and save values, such as an ID, for the next requests. A collection can be run through Runner or Postman CLI in CI. Middle/Senior: I make sure a collection is a repeatable test: nothing hard-coded, one authorisation at the collection level, a chain of requests that creates and removes its own data, and assertions that describe the contract and not only the status. I do not leave secrets in the shared value. When the set grows I move it to code in a repository and keep Postman for exploration and reproducing bugs.

What is Swagger and how do you use it?

OpenAPI is a format for describing an HTTP API in JSON or YAML, and Swagger is the set of tools around it, such as Swagger UI. QA reads the specification as a contract and derives tests: required fields, limits, enums, error codes. A mismatch with behaviour may be a code bug, a documentation bug or an unsettled requirement, so it is raised as a bug or question.

QA Fundamentals · Manual API testing

In Swagger a field is required, yet the API accepts a request without it. Whose mistake is it?

The specification says currency is required, but the API accepted a transfer without it and debited in a default currency. The tester does not know what to do: fix the documentation, file a bug or ask. Is it an error when the code and the description disagree? A mismatch like this is exactly what QA looks for. This lesson is about what OpenAPI and Swagger are, how to read a specification as a source of tests and where it lets you down.

How it works and why. OpenAPI (formerly the Swagger Specification) is a format for describing an HTTP API in JSON or YAML: paths, methods, parameters, schemas of request and response bodies, response codes, authorisation schemes. Swagger is the name of the set of tools around it: Swagger UI shows the specification as interactive documentation with a "Try it out" button, Swagger Editor helps to write it and Codegen generates code. The current line is OpenAPI 3.x; older projects still have Swagger 2.0. The idea is that the contract between client and server exists in a machine-readable form instead of in a developer's head. From one file the tools take documentation, requests and stubs.

One file, many uses

OpenAPI fileSwagger UIPostmanTest casesMock server
Figure 1. One OpenAPI file feeds the documentation, a request collection, test cases and a mock server.

Example: from "tried it in Swagger" to tests from the specification. A simplified fragment for creating a transfer:

{
  "openapi": "3.0.3",
  "paths": { "/transfers": { "post": {
    "requestBody": { "required": true, "content": {
      "application/json": { "schema": {
        "$ref": "#/components/schemas/NewTransfer" } } } },
    "responses": {
      "201": { "description": "Created" },
      "400": { "description": "Validation error" },
      "401": { "description": "No or invalid token" } }
  } } },
  "components": { "schemas": { "NewTransfer": {
    "type": "object",
    "required": ["amount", "currency"],
    "properties": {
      "amount": { "type": "number", "minimum": 0.01 },
      "currency": { "type": "string", "enum": ["UAH", "EUR"] }
    } } } }
}

Before: opened Swagger UI, pressed "Try it out", sent a request with valid values, got 201 and moved on. After: every line of the specification becomes a test, and each word "required", "minimum", "enum" becomes a boundary condition:

Spec line                          Test
required: amount, currency         no amount → 400; no currency → 400
amount: number, minimum 0.01       0.01 → 201; 0 → 400; "10" (a string) → 400
currency: enum UAH, EUR            "UAH" → 201; "USD" → 400; "uah" → 400?
responses: 201, 400, 401           no token → 401; no other codes in the spec

Actual: amount = 0 → 422 Unprocessable Entity   (the spec says 400)

The last line is a typical find: the spec says 400, the API answers 422. It is not necessarily a bug in the code, there are three options. A mistake in the documentation (the code is right, the spec must be fixed), a mistake in the code (the contract matters for clients that already expect 400) or an unsettled requirement (the team has not agreed yet). QA's role is to show the mismatch in time and ask, not to decide alone. And if clients already depend on the code's behaviour, changing the status may become a breaking change.

Limits and alternatives. A specification does not guarantee behaviour, it only describes it. If it is written by hand, it drifts from the code; if it is generated from the code, it reflects what the code does and cannot find a mistake in the implementation. So it works as a requirement only when it is maintained together with development and CI has a conformance check (contract testing). Version specifics: in OpenAPI 3.0 a nullable flag allows null, while in 3.1 the schemas are aligned with JSON Schema and the type is written as an array, for example ["string", "null"]. A separate Swagger UI trap: the servers list may point to a real environment, and "Try it out" with the Authorize button sends real requests with a real token. Before pressing Execute on a DELETE, check which server it goes to. Sometimes there is a Postman collection or just a Confluence page instead of OpenAPI; then requirements are collected from them and from developers, and a specification appears as a result of testing.

Common mistakes.

  • Trusting the specification without checking: it may lag behind the code, and a test based on a stale description gives false bugs.
  • Checking only the 200 case from "Try it out": the spec describes error codes, and each needs a test.
  • Pressing "Execute" without looking at the server: the request may hit a shared or even a production environment.
  • Settling a mismatch alone: changing the expectation to match the API's behaviour without discussion, because "that is how it works". The defect then becomes the norm.
  • Not adding negative examples: the specification says what is allowed, and what is forbidden needs checking too.

Check yourself

In the specification amount has "minimum": 0.01. Which values do you take for tests and what do you expect?

Answer

Boundaries: 0.01 (accepted, 201), 0.009 and 0 (rejected, 400), a negative number (400). Also values of other types: the string "10", null, a missing field (400). Plus typical ones: an ordinary amount and a large one. Expected codes come from the specification, and where it is silent (say, 0.009 with three decimals) we ask the team, because it is also a rounding question.

The API returns 422 while the specification says 400 for this error. Which three conclusions are possible and what do you do?

Answer

A mistake in the documentation, a mistake in the code or an unsettled requirement. I collect evidence (request, response, a quote from the specification), file a bug or a question in the tracker and involve the developer and the PO, because the team has to decide what is right. Separately I check whether clients already depend on the current behaviour: then changing the code would become a breaking change.

In an interview. Junior: Swagger is API documentation in the OpenAPI format where you can send requests from the browser. I use it as the requirements for the API, for quick checks and to look for mismatches between the documentation and the real behaviour. The specification can be imported into Postman. Middle/Senior: I read the specification as a contract and derive tests from it: required fields, boundaries, enums, response codes. I do not settle a mismatch between the description and the behaviour alone but raise it as a bug or a question, because the mistake may be in the code or in the documentation. I make sure the specification does not drift: generation from code or a conformance check in CI. In Swagger UI I check which server a request goes to.

What is idempotency and why test it?

An idempotent operation has the same server effect repeated as done once, so a retry creates no duplicate. Per RFC 9110, GET, PUT and DELETE are idempotent and POST is not (nor PATCH, per RFC 5789). The effect counts, not the response: a repeated DELETE returning 404 is fine. POST in payments relies on an Idempotency-Key. Tests cover retries, the same key with another body, concurrency and database state.

QA Fundamentals · Manual API testing

A user pressed "Pay" twice. How many debits will there be?

A client app sent a payment, the network flickered, no response. The user presses "Pay" again, and the mobile client automatically repeats the request after a timeout. The server may have processed the first request completely, and only the response was lost. Without protection this is two debits for one purchase. This lesson is about what idempotency is, which HTTP methods have it by definition, how it is provided for POST and what exactly to check.

How it works and why. The HTTP specification (RFC 9110) defines two different concepts. A method is safe if it does not imply changing server state: GET, HEAD, OPTIONS. A method is idempotent if the effect on the server of several identical requests is the same as of one: PUT and DELETE, as well as all safe methods. POST is not idempotent: two identical POSTs create two resources. PATCH does not guarantee idempotency either: "set status to paid" can be repeated, but "increase the balance by 10" cannot. Importantly, idempotency concerns the effect on the server, not the response: a repeated DELETE may return 404 instead of 204, and that is fine, the resource is already gone.

Why it matters. A client cannot know whether a request arrived when no response came. So network libraries, gateways and users themselves repeat requests. For idempotent methods a retry is safe by default. For payments, order creation and sending emails it has to be made safe: the client adds a unique key to the POST (the Idempotency-Key header, a common practice described by an IETF draft), and the server remembers the pair "key → result". A repeated request with the same key does not perform the operation but returns the stored response.

A retry after a lost response

ClientServerPOST, key Kdebit (once)response lostPOST, key K (retry)key K is knownthe same response
Figure 1. The server performed the debit once. For the retry with the same key it answered with the stored result.

Example: from two debits to one. Without a key, a repeated POST /payments created two records, and a database query showed it: two rows with the same amount and account. After the team added key support, the check looks like this:

POST /api/payments HTTP/1.1
Idempotency-Key: 7c1e4b5a-3f0d-4a39-9b1e-2d6f0a8c11aa
Content-Type: application/json

{"account": "acc-1", "amount": 250.00, "currency": "UAH"}

HTTP/1.1 201 Created
{"id": "p-9001", "status": "pending"}

# a retry with the same key and the same body
HTTP/1.1 201 Created
{"id": "p-9001", "status": "pending"}

# the same key, but amount = 999.00
HTTP/1.1 4xx   (we expect a refusal, not a second debit)

How to read it. The first and second requests return the same id, so the payment was created once. The third check is the least obvious: the same key with a different body means the client reused a key by mistake, and the server must refuse with an explicit 4xx error rather than silently perform a second operation or return the old response for a different body. The exact code depends on the API (the IETF draft suggests 422), so take it from the specification. For the final conclusion we do not rely on the response: the database must hold one row with this key, and the balance must be debited once.

The same retry with and without a key

No key

Two debits

Each POST creates a new payment. A double click or a retry after a timeout produces a duplicate, and the money is debited twice.

With a key

One debit

The server recognises the key and returns the same result. There is no duplicate even if the client retried several times.

Figure 2. A key turns a dangerous retry into a safe one. This is confirmed by the state in the database, not only by the response.

Limits and alternatives. A key does not solve everything. Key scope: it is usually bound to a client or user, otherwise a coincidence with someone else's key would return someone else's response. Keys do not live forever, they get an expiry (say, a day), and after it a retry will be executed again: worth knowing and checking. The hardest check is concurrent requests with the same key: if the server first checks and then writes, two parallel requests may both consider the key new. Reliable protection lives at the database level (a unique constraint on the key) or in locking, and QA checks it by sending two requests simultaneously. There are other approaches too: natural keys (a unique order number), resource versioning (If-Match with an ETag) and PUT instead of POST when the client sets the identifier. Idempotency is worth having in a message queue as well: a consumer may receive one event twice.

Common mistakes.

  • Thinking idempotent means "returns the same response": it is about the effect, not the response. A repeated DELETE with 404 does not break the rule.
  • Checking only the response to the retry: it may be right while two records sit in the data. Look at the state.
  • Not checking the same key with a different body: a client mistake reaches production silently.
  • Testing the retry only sequentially: the race of two simultaneous requests breaks exactly where a sequential test sees nothing.
  • Treating PUT and PATCH alike: PUT replaces the resource completely, while PATCH depends on how the server implemented the change.
  • Forgetting a GET with side effects: a method that should be safe changes data, and every page prefetch or crawler becomes an operation trigger.

Check yourself

DELETE /orders/42 returns 204 the first time and 404 the second. Is that a violation of idempotency?

Answer

No. Idempotency is about the effect on the server: after the first and after the second request the state is the same, order 42 does not exist. A difference in the response does not violate the definition. It would be a bug if the second DELETE removed something else or returned 500.

Two parallel POST /payments requests with the same Idempotency-Key created two payments. Where is the defect most likely and how do you confirm it?

Answer

The server first checks whether the key is known and then writes, without atomicity: both requests passed the check before the first one stored the key. To confirm: send two requests at once and run an SQL check for the number of rows with this key. The fix is at the database level: a unique constraint on the key or locking.

In an interview. Junior: An idempotent operation gives the same effect when repeated. GET, PUT and DELETE are idempotent, POST is not. I check that a repeated request, for example after a double click or a retry after a timeout, does not create a duplicate. Middle/Senior: I distinguish safe from idempotent and look at the effect, not the response. For POST in payments I check Idempotency-Key: a retry with the same body gives the same response and one record in the database, the same key with a different body is rejected, and two simultaneous requests do not create a duplicate. I also ask about the scope and the lifetime of a key. I confirm with the state in the database and with reconciliation, because the API response may be right while a duplicate sits in the data.

How do you test authentication and authorisation in an API?

Authentication answers who the caller is (failure gives 401), authorization what they may do (failure gives 403). Authorization is checked at three levels: function, object (whose record) and field. A 200 with someone else's data is always a bug (BOLA, also called IDOR). A matrix of role × endpoint × whose resource × operation is built, and after a write the other user's resource is checked unchanged, since a 403 alone does not guarantee that.

QA Fundamentals · Manual API testing

A request with someone else’s ID returned 200 with data. Is it a bug or by design?

A tester checked API security: no token returns 401, an ordinary user on an admin method returns 403. All as planned. Then they put another user's order number in the address and got 200 and someone else's data. Authentication and role work, but access to an individual object does not. This lesson is about how authentication differs from authorisation, which three levels of checks the server has and how to build a test matrix that does not let others' data through.

How it works and why. Authentication answers "who are you?": a token, an API key, a session. A failure is 401 (per RFC 9110 a 401 response must carry a WWW-Authenticate header; for Bearer tokens RFC 6750 describes error="invalid_token"). Authorisation answers "what are you allowed to do?". A failure is 403: the identity is known but the action is forbidden. Authorisation has several levels, and each is needed separately, because a violation at each gives its own class of vulnerability. In the OWASP API Security Top 10 (2023) these are API1 Broken Object Level Authorization, API3 (the property level) and API5 Broken Function Level Authorization.

Three checks, in this order

1. Is the token valid?2. Does the role allow it?3. Is it their resource?200 and data401403403 or 404
Figure 1. The server asks in turn: who are you, what may you do and is it yours. The third check is the one most often missing.

The levels are: a function check (may the role perform this operation: an ordinary user does not call admin methods), an object check (does this record belong to the user: BOLA, informally IDOR) and a field check (may they see or change this field: not setting role: admin for themselves through the request body). For someone else's object the server returns 403 or 404. 404 is often chosen on purpose so as not to confirm that such a resource exists. Both are fine as long as the team has set a policy and follows it. What matters is something else: a 200 with someone else's data is always a bug.

Example: from three checks to a matrix. The first test plan had three lines: no token, an expired token, an ordinary user on an admin method. All passed. The fourth test added a new dimension, "resource owner":

# the token of user A (user-a), order 9001 belongs to user B
GET /api/orders/9001 HTTP/1.1
Authorization: Bearer <token of user-a>

HTTP/1.1 200 OK
{"id": 9001, "owner": "user-b", "total": 1280.00, "card": "**** 4242"}

This is a typical BOLA: the server checked the token and the role (an ordinary user is allowed to read orders) but did not compare whose record it is. The fix is obvious in code: the database query gets an owner condition. For the tester the conclusion is different: the matrix must contain not only "who" but also "whose resource" and "which operation". A minimal matrix for one resource:

RequestExpectation
No token401
An expired, forged or truncated token401
A token from another environment or for another service (audience)401
An ordinary user, an admin method403
User A reads, changes (PUT, PATCH) or deletes the resource of B403 or 404, the data is unchanged
A list of resources for user Aonly their records, none of someone else's
Their own resource with the right role200 and the right fields

A write test needs an extra step: after user A's request to the resource of B, check that the resource of B did not change (a GET as B), because a 403 response alone guarantees nothing if the change happened anyway.

Limits and alternatives. Tokens deserve separate attention. For a JWT you check the signature, the expiry (exp), the issuer (iss) and the audience (aud). After a user logs out, a short-lived access token that is validated without a store lookup usually stays valid until it expires. So "the token does not work after logout" depends on the implementation: check that the refresh token is revoked, and if the team promises immediate revocation, that a denylist works. There are other models too: API keys, cookie sessions (where the CSRF question is added) and OAuth 2.0 with scopes: a token with the read scope must not pass a write. Automating the matrix of roles and endpoints fits parameterised tests well. Manual checking remains for new endpoints. Brute force and lockout on login belong to security separately.

Common mistakes.

  • Checking only 401 and 403 at the function level: BOLA at the object level stays outside the tests.
  • Testing only reads: someone else's resource may be unreadable by GET but changeable via PUT or DELETE.
  • Taking a 403 as proof without checking the state: after the request the other user's resource must remain unchanged.
  • Substituting only sequential IDs: unpredictable UUIDs make enumeration harder but do not replace the owner check.
  • Mixing up 401 and 403: "no or invalid token" and "a token but no rights" are different bugs with different fixes.
  • Not checking lists and search: a single resource may be protected while the collection returns others' records.

Check yourself

A request with an ordinary user’s token to an admin endpoint returned 401 instead of 403. Is it a bug?

Answer

Most likely yes. The token is valid, the identity is established, so the correct response is 403: the action is forbidden. 401 means authentication failed. But first find out: is the token not expired and has the policy not changed (some services deliberately answer the same way so as not to reveal the API structure). If the specification says 403 and the API gives 401, that is a mismatch to raise as a bug.

User A sent a PUT to the resource of user B and got 403. Is that enough to conclude "protected"?

Answer

No. You need to make sure the resource of B did not change: a GET as B and, where possible, a database check. A 403 response may hide a change that has already happened if the owner check runs after the write or the access axis is broken in another method.

In an interview. Junior: I check requests with no token and with an expired token: it must be 401, and with a token without the needed rights 403. The most important thing is whether a user can get someone else's data by substituting another ID: that is an IDOR vulnerability. And that after logout the session cannot be renewed: the refresh token is revoked. Middle/Senior: I distinguish three levels of authorisation: function, object, field. I build a matrix "role × endpoint × whose resource × operation" and for writes I check that the other user's resource did not change. For a JWT I look at the signature, exp, aud and iss, and after logout I clarify how revocation is implemented: an access token often lives until it expires. I agree the 403 or 404 policy for others' resources with the team and check that it is the same on all endpoints.