0% found this document useful (0 votes)
28 views4 pages

API Testing: Authentication & Methods Guide

This document discusses various topics related to API testing including what to test, common protocols used, types of API testing, status codes, and differences between key terms like API and web service. It provides an overview of common steps for API testing such as selecting test cases, developing API calls, configuring parameters, validating responses, and executing calls.

Uploaded by

Nandu Krish
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views4 pages

API Testing: Authentication & Methods Guide

This document discusses various topics related to API testing including what to test, common protocols used, types of API testing, status codes, and differences between key terms like API and web service. It provides an overview of common steps for API testing such as selecting test cases, developing API calls, configuring parameters, validating responses, and executing calls.

Uploaded by

Nandu Krish
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

1.

Parse Complex JSON


2. Status Code
3. 401 and 403
4. What is Authentication ?
5. What is Authorisation ?
6. What is the difference between Authentication and Authorisation ?

API testing - What to test ?

- CRUD - Resource creation, updation, deletion


- Missing required functionality
- Proper messaging
- Reliability
- Multithreading and improper handling issues
- Repetition

JSON / XML Schema validation


Max, min, invalid, null values

Challenges
- How to maintain the flow - response of one request to pass to another test
- Different types of param validation
- Validation of input
- Validation of output
- parameter categorisation

Common protocol used in API


- Rest (Representational State transfer protocol) - design pattern to create apis | stateless |
Client - Server |Layered sys Encapsulation
- Soap
- http
- JMS & UDDI

Types of API testing


- Validation
- Functional
- Load
- Run time error
- Security (vulnerabilities, threats etc)
- Penetration testing

What is a resource in REST ?


- Any Content (HTML, Image, Files)

How to represent resources (Common ways)


- JSON and XML

Which protocol Rest WebService use ?


- HTTP

What is Difference Between API and WebService


- WebService - need a network to operate
- API dont need network for operation (send requests thru endpoints)

What is the difference between PUT and POST ?


- PUT - Create / Update
- POST - Post is used to create

RPC - Remote Procedure call


- Executing procedures on remote / different machine

GET
- retrieve resource from end point
- remain in browser history / bookmarked (so no sensitive info)

POST
- Create resource
- Never cache/ bookmarked / never remain in browser history
- No restriction on data length

PUT
- Create / Update
- Never cache

PATCH
- update partial resource

DELETE
- delete

OPTIONS
- returns all options and available HTTP methods
HEAD - returns the header info (get)
TRACE - trace the request
Status Code
200 - ok - Successful Post request
201 - new resource created

400 - Bad Request


404 - Not found
401 - Unauthorised
403 - Forbidden

500 - Internal Server error

What is HTTP Request Contained ?


- Request Method
- base URI + resource URL
- Request Header - Accept-Language, Accept-Encoding, Host, User-Agent etc
- Request Body

What is HTTP Response Contains?


- Status Code
- Response Header Fields - Date, Server, Last-Modified, Content-Type
- Response Body

Common Steps for API testing


- Select the test case
- Develop API call
- Configure the API params
- Determine how to validate the API response
- Execute the API call
- API call response - validate the data
Constraints of API - 6 constraints

Common questions

Powered by AI

Key aspects of validating JSON or XML schema in API testing include ensuring that the data adheres to expected structure and constraints such as required fields, data types, and allowable values (e.g., max, min, invalid, null). Effective validation checks the completeness and correctness of the data format, ensuring compatibility with other system components. This process often involves using schema validation tools that automatically verify data against predefined schema models .

The OPTIONS HTTP method is significant in API testing as it allows clients to determine what HTTP methods and other options are available for a particular resource, providing metadata about the resource without transferring any data themselves. This can be particularly useful in testing to check the supported actions on endpoints and ensure compliance with CORS policies. The OPTIONS method communicates allowed interactions and assists in debugging by revealing communication capabilities between the client and server .

RESTful APIs are defined by six constraints that shape their architecture: statelessness, where each request from a client must contain all the information the server needs to fulfill it; client-server architecture that separates concerns between interface and storage; layered system to enhance scalability by enabling components to be independently deployed; cacheability to improve performance by storing response data; uniform interface, which simplifies and decouples the architecture; and code-on-demand to extend client functionality by downloading scripts on demand. These constraints ensure that APIs are scalable, flexible, and easy to maintain .

HTTP status codes are pivotal in API testing as they indicate the result of a client's request. Specifically, the code 401 signifies 'Unauthorized,' meaning the request requires user authentication. In contrast, 403 means 'Forbidden,' indicating that the server understood the request, but it refuses to authorize it. These codes help testers determine not only outcome validity but also potential issues in authentication and permissions settings .

SOAP (Simple Object Access Protocol) and REST (Representational State Transfer) serve different roles in web services. SOAP is a protocol with a formal set of rules for defining messages and is highly extensible, providing a strict communication layer that includes built-in security and transactional reliability. It is suitable for operations requiring formal contracts between the client and server or when operations require complex interactions. REST, on the other hand, is an architectural style leveraging the stateless HTTP protocol, which is more flexible and easier to implement with CRUD operations. REST is ideal for web APIs that require scaling and accessible resources over the web, focusing on simplicity and performance .

Challenges in API testing include maintaining the flow, where responses of one request need to be passed to another test. To manage this, proper test data management and automation scripts can be employed to handle dependencies between requests. Another challenge is parameter validation, including differentiating between types of parameters and validation of both input and output. Effective strategies involve comprehensive test planning and use of validation frameworks that help categorize and validate parameters appropriately .

The HTTP TRACE method is used to perform a message loop-back test along the path to the target resource, useful for diagnosing the connections and communication paths between the client and server. It provides a mechanism for debugging to see what is being received at the other end of the request chain and what manipulations are being applied along the way. However, its use is limited due to security concerns, as it can potentially be exploited in Cross-Site Tracing (XST) attacks to steal information such as cookie data .

Authentication is the process of verifying the identity of a user or entity that is attempting to access a system. It is the first step before authorization, which involves determining whether the authenticated user is permitted to access the resources they have requested. The critical difference is that authentication is about confirming identity, while authorization is about granting access to resources based on that identity .

In RESTful APIs, PUT and POST serve different purposes. PUT is idempotent, meaning multiple identical requests will produce the same effect as a single request, primarily used for creating or updating resources. POST, however, is used to create resources and is not idempotent, as repeated requests will not yield the same result as a single request due to changes in resource state. PUT should be used when the client is sending a complete representation of a resource to the server, while POST should be used to create or process subordinate resources .

Effective error handling enhances API reliability by providing clear, consistent, and informative responses for failure scenarios, allowing clients to understand and properly handle errors. Common patterns include using standardized status codes to represent specific errors consistently, providing descriptive messages that explain what went wrong, and suggesting corrective actions. Additionally, logging errors for further analysis helps to monitor and improve API performance over time. These practices ensure robust communication and improve the client experience when interacting with the API .

You might also like