Tuesday, February 14, 2023

Forward proxy vs Reverse proxy

 Forward Proxy

---------------
A forward proxy, also known as a "proxy server," or simply "proxy," is a server that sits in front of one or more client machines and acts as an intermediary between the clients and the internet. When a client machine makes a request to a resource on the internet, the request is first sent to the forward proxy. The forward proxy then forwards the request to the internet on behalf of the client machine and returns the response to the client machine.

A forwards proxy is mostly used for:
1. Client Anonymity
2. Caching
3. Traffic Control
4. Logging
5. Request/Response Transformation
6. Encryption

Reverse Proxy
---------------
A reverse proxy is a server that sits in front of one or more web servers and acts as an intermediary between the web servers and the Internet. When a client makes a request to a resource on the internet, the request is first sent to the reverse proxy. The reverse proxy then forwards the request to one of the web servers, which returns the response to the reverse proxy. The reverse proxy then returns the response to the client.

A reverse proxy is mostly used for:
1. Server Anonymity
2. Caching
3. Load Balancing
4. DDoS Protection
5. Canary Experimentation
6. URL/Content Rewriting




Monday, February 13, 2023

SOAP API

 SOAP ( Simple Object Access Protocol ) is a messaging protocol that allows programs that run on disparate operating systems or services like frontend or backend to communicate using HTTP and its extensible markup language ( XML)



SOAP uses WSDL is an XML format for describing network services as a set of endpoints operating on messages containing either document-oriented or procedure-oriented information.

what to Test in API testing 


Validate the keys with Min and Max range of APIS

Have a testcase to do XML, JSON schema validation

keys verification. If we have JSON , XML apis we should verify its that all the keys are coming.

Verify that how the APIs error codes handled.




what is API ? In a easy language

 API stands for the Application Programming Interface, They are basically a collection of functions and procedures which allows us to communicate two application or library.


For example : 

It like a connector as seen in the picture. All data connects to our organization through API.






In one line, API is its an interface between different software programs or service.


Restaurant API example:


API is the messenger that takes your order(waiter) and tells the system(kitchen) what to do (to prepare food) and in return gives back the response you asked (waiter returns with the ordered food).

Types of APIs 


we are only concern about the Web API 

Simple Object Access Protocol ( SOAP )
Remote Procedure Call (RPC)
Representational State Transfer (REST)


what is API ?

API testing is testing that APIs and its integration with the services

In this guide, we are basically discussing about the REST API Testing. Where we need to test the REST APIs for the validation, error codes and load testing.

What is REST API ?

As REST is an acronym for REPRESNTATIONAL STATE TRANSFER, statelessness is key. An API can be REST if it follows the below constraints.

The REST architecture style describes six constraints:

1. uniform interface 2. stateless 3. cacheable 4. client server 5. layered system 6. code on demand.

Uniform interface : Uniform interface constraint defines the interface between clients and servers.

In other terms : First constraint of the REST API states that the client and server has to communicate and agree to certain rules based on resources (they should communicate with same resource like json, xml, html, txt) and with proper encoding like UTF-8 extra.

Another point they should communicate with the self-descriptive Messages e.g: Use the same MIME types.

Stateless

APIs in REST are stateless and Client and Server does not worry about the state of the request or response.


cacheable

According to the WWW, clients can cache responses. Responses should therefore, implicitly or explicitly, define themselves as cacheable, its upto server when they want the cache to expired etc.

Client-server

Client and server are two different entity, it means that servers and clients may also be replaced and developed independently as long as the interface is not altered.

Layered system

It  means that the between client and server there can be any number of layered systems it does not matter.

Code on Demand 

Server can store the code or logic to themselves and transfer it whenever needed rather client side logic.


Sunday, February 12, 2023

Write REST APIs IN PYTHON - ROUTER

 In FastAPI, a router is a mechanism for grouping a set of related endpoints and applying common functionality to all of them, such as prefixing their URLs or applying middleware to all requests to the endpoints.


Routers are created using the APIRouter class in FastAPI, which provides a convenient way to define multiple routes in a single place, and then include all of those routes in your main FastAPI application using the include_router method.

For example, if you have a set of endpoints for managing items in an e-commerce website, you could define all of those endpoints in a single file using an APIRouter and then include the router in your main FastAPI application. This would allow you to apply common functionality to all of those endpoints such as adding an authentication middleware to ensure that only authorized users can access the endpoints.

The main advantage of using routers in FastAPI is that they allow you to organize your application into smaller, more manageable parts making it easier to maintain and extend your code.

# File endpoints/items.py 

from fastapi import APIRouter

router = APIRouter()

@router.get("/{item_id}")

async def read_item(item_id: int, q: str = None):

         return {"item_id" : item_id, "q" : q}


@router.put("/{item_id}")

async def update_item(item_id: int, q: str = None):

         return {"item_id" : item_id, "item" : item}



# File main.py

from fastapi import FastAPI

from .endpoints import items 


app = FastAPI()

app.include_router(items.router, prefix="/items")














Tuesday, January 17, 2023

𝗢𝗔𝘂𝘁𝗵, 𝗢𝗜𝗗𝗖 𝗮𝗻𝗱 𝗦𝗔𝗠𝗟

 To clarify the difference, we need to first define what authentication and authorization is. 


Authentication is the process of verifying the identity of a user or device, 

while authorization is the process of determining what a user or device is allowed to do, after his identity is established.


TL;DR:
OAuth is for allowing access to someone else's resources

OIDC is for verifying who you are and allowing access to someone else's resources

SAML is for gaining access to different resources from different places with one card.

- OAuth (Open Authorization)
OAuth (2.0) is an open standard for providing and implementing authorization. It provides secure delegated access. That means, an application can act as a user and access endpoints or take action on servers as this user, but without requiring the user to log in or share his credentials. This access is temporary and is used, for example, to access a users contact list in Facebook.

- OIDC (OpenID Connect)
OpenID Connect is an open standard / open source solution for providing and implementing an authentication process. Most of the big tech companies like Google, Microsoft or GitHub support this standard. It allows users to choose the third-party OpenID provider they want to use to login to any website that accepts the OpenID standard (which could be also yours). If you previously used your Google Account to log in to Spotify or any other platform, you've seen OIDC in action. OpenID is useful for app and website developers who want to authenticate users, but are not willing to take the risk of storing user records on their own due to security aspects. You can see it as SSO for consumer applications.

- SAML (Security Assertion Markup Language)
SAML is an open standard for authentication and authorization and is used mostly in enterprises. It's a framework for single-sign on (SSO), what means that if you successfully logged in to an application of your organization, you can also access other apps without the need to re-enter your credentials. SAML uses XML to exchange authentication and authorization messages between the specific identity providers to verify user identity and permissions, if access to an application is granted or denied. It can be seen as SSO for enterprise applications.

Tuesday, June 28, 2022

DATA INFRASTRUCTURE

 








OOPS concepts

 OOPS:

OOPS is abbreviated as Object Oriented Programming system in which programs are considered as a collection of objects. Each object is nothing but an instance of a class.


basic concepts of OOPS:

Abstraction

Encapsulation

Inheritance

Polymorphism


Class:

A class is simply a representation of a type  of object. It is the blueprint/plan/template that describes the details of an object.

object:

An object is an instance of a class. It has its own state, behavior and identity.


Encapsulation:

Encapsulation is an attribute of an object, and it contains all data which id hidden. That hidden data can be restricted to the members of that class.

Levels are Public, private , Protected , Internal and Protected Internal.


Polymorphism:

Polymorphism is nothing but assigning behavior or value in a sub-class to something that was already declared in the main class. Simply polymorphism takes more than one form.


Inheritance:

Inheritance is a concept where one class shares the structure and behavior defined in another class. If Inhertiance applied to one class is called single inheritance and if it depends on multiple classes, then it is called multiple inheritance.


Manipulators:

Manipulators are the functions which can be used in conjunction with the insertion (<< ) and extraction (<< ) operators on an object. Examples are endl and setw.


Constructors:

A  constructor is a method used to  initialize  the state of  an object and it gets invoked at the time of object creation. Rules for constructor are 

Constructor Name should be the same as a class name 

A constructor must have no return type.

Destructor:

A destructor is a method  which is automatically called when the object is made of scope or destroyed. Destructor name is also same as class name but with the tilde symbol before the name.


Inline function:

An inline function is a technique used by the compilers and instructs to insert complete body of the function whereever that function is used in the program source code.


Virtual function:

A virtual function is a member function of a class and is functionality can be overridden in its derived class. This function can be implemented by using a keyword called virtual an it can be given function declaration.

A virtual function can be declared using a token(virtual) in C++. It can be achieved in  C/PYTHON language by using function pointers or pointers to function.


Friend function 

A friend function is a friend of a class that is allowed to access to public, private or protected data in that same class. If the function is defined outside the class cannot access such information.


A friend can be declared  anywhere in the class declaration and it cannot be affected by access control keywords like private, public or protected.


Function  overloading:

Function overloading is a regular function, but it is assigned with multiple parameters. It allows the creation of several methods with the same name which differ from each other by the type of input and output of the function.


Example


void add(int& a, int& b);

void add(doubles& a,  doubles& b);

void add(struct bob& a, struct bob& b);


Operator overloading:


Operator overloading is a function where different operators are appiled and depends on the arguments. Operator  -,* can be  used to pass through the function and it has its own precedence to execute.


Abstract class:

An abstract class is a class which cannot be instantiated.  Creation of an object is not possible with an abstract class, but it can be inherited. An abstract class can contain only an Abstract method. Java allows only abstract method in abstract class while other languages allow non-abstract method as well.

Ternary operator:

The ternary operator is said to be an operator which takes three arguments. Arguments and results are of different data types and it depends on the function. The ternary operator is also called a conditional operator.

Finalized method:

Finalized method helps to perform cleanup operations on the resources which are not currently used. Finalized method is protected and it is accessible only through this class or by a derived class.

Different types of arguments:

A parameter is a variable used during the declaration of the function or subroutine and arguments are passed to the function body and it should match with the parameter defined.

There are two types of arguments:

Call by value - Value passed will get modified only inside the function, and it returns the same value whatever it is passed into the function.

Call by reference - Value passed  will get  modified in both inside and outside the functions and it returns the same or different value.