Created
August 8, 2024 05:23
-
-
Save encikpulasan/f0b5a90e510d09a6304e4e5f103ba9cc to your computer and use it in GitHub Desktop.
Postman Request Collection for Auth
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "info": { | |
| "_postman_id": "c37aa390-aa58-48bc-9e53-8716daff537a", | |
| "name": "Auth", | |
| "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", | |
| "_exporter_id": "34921941" | |
| }, | |
| "item": [ | |
| { | |
| "name": "User Registration", | |
| "event": [ | |
| { | |
| "listen": "test", | |
| "script": { | |
| "exec": [ | |
| "pm.test(\"Status code is 201\", function () {", | |
| " pm.response.to.have.status(201);", | |
| "});", | |
| "", | |
| "pm.test(\"Body contains success message and userId\", function () {", | |
| " var jsonData = pm.response.json();", | |
| " pm.expect(jsonData.message).to.eql(\"User registered successfully\");", | |
| " pm.expect(jsonData.userId).to.be.a('number');", | |
| " pm.collectionVariables.set(\"userId\", jsonData.userId);", | |
| "});" | |
| ], | |
| "type": "text/javascript" | |
| } | |
| } | |
| ], | |
| "request": { | |
| "method": "POST", | |
| "header": [], | |
| "body": { | |
| "mode": "raw", | |
| "raw": "{\n \"username\": \"newuser{{$timestamp}}\",\n \"password\": \"newpassword123\"\n}", | |
| "options": { | |
| "raw": { | |
| "language": "json" | |
| } | |
| } | |
| }, | |
| "url": { | |
| "raw": "{{baseUrl}}/auth/register", | |
| "host": [ | |
| "{{baseUrl}}" | |
| ], | |
| "path": [ | |
| "auth", | |
| "register" | |
| ] | |
| } | |
| }, | |
| "response": [] | |
| }, | |
| { | |
| "name": "Basic Authentication", | |
| "event": [ | |
| { | |
| "listen": "test", | |
| "script": { | |
| "exec": [ | |
| "pm.test(\"Status code is 200\", function () {", | |
| " pm.response.to.have.status(200);", | |
| "});", | |
| "", | |
| "pm.test(\"Body contains success message\", function () {", | |
| " var jsonData = pm.response.json();", | |
| " pm.expect(jsonData.message).to.eql(\"Basic authentication successful\");", | |
| "});" | |
| ], | |
| "type": "text/javascript" | |
| } | |
| } | |
| ], | |
| "request": { | |
| "method": "POST", | |
| "header": [], | |
| "body": { | |
| "mode": "raw", | |
| "raw": "{\n \"username\": \"newuser{{$timestamp}}\",\n \"password\": \"newpassword123\"\n}", | |
| "options": { | |
| "raw": { | |
| "language": "json" | |
| } | |
| } | |
| }, | |
| "url": { | |
| "raw": "{{baseUrl}}/auth/basic", | |
| "host": [ | |
| "{{baseUrl}}" | |
| ], | |
| "path": [ | |
| "auth", | |
| "basic" | |
| ] | |
| } | |
| }, | |
| "response": [] | |
| }, | |
| { | |
| "name": "JWT Authentication", | |
| "event": [ | |
| { | |
| "listen": "test", | |
| "script": { | |
| "exec": [ | |
| "pm.test(\"Status code is 200\", function () {", | |
| " pm.response.to.have.status(200);", | |
| "});", | |
| "", | |
| "pm.test(\"Body contains token\", function () {", | |
| " var jsonData = pm.response.json();", | |
| " pm.expect(jsonData.token).to.be.a('string');", | |
| " pm.collectionVariables.set(\"jwtToken\", jsonData.token);", | |
| "});" | |
| ], | |
| "type": "text/javascript" | |
| } | |
| } | |
| ], | |
| "request": { | |
| "method": "POST", | |
| "header": [], | |
| "body": { | |
| "mode": "raw", | |
| "raw": "{\n \"username\": \"newuser{{$timestamp}}\",\n \"password\": \"newpassword123\"\n}", | |
| "options": { | |
| "raw": { | |
| "language": "json" | |
| } | |
| } | |
| }, | |
| "url": { | |
| "raw": "{{baseUrl}}/auth/jwt", | |
| "host": [ | |
| "{{baseUrl}}" | |
| ], | |
| "path": [ | |
| "auth", | |
| "jwt" | |
| ] | |
| } | |
| }, | |
| "response": [] | |
| }, | |
| { | |
| "name": "Protected Route", | |
| "event": [ | |
| { | |
| "listen": "test", | |
| "script": { | |
| "exec": [ | |
| "pm.test(\"Status code is 200\", function () {", | |
| " pm.response.to.have.status(200);", | |
| "});", | |
| "", | |
| "pm.test(\"Body contains access granted message\", function () {", | |
| " var jsonData = pm.response.json();", | |
| " pm.expect(jsonData.message).to.eql(\"Access granted to protected route\");", | |
| " pm.expect(jsonData.userId).to.be.a('number');", | |
| "});" | |
| ], | |
| "type": "text/javascript" | |
| } | |
| } | |
| ], | |
| "request": { | |
| "auth": { | |
| "type": "bearer", | |
| "bearer": [ | |
| { | |
| "key": "token", | |
| "value": "{{jwtToken}}", | |
| "type": "string" | |
| } | |
| ] | |
| }, | |
| "method": "GET", | |
| "header": [], | |
| "url": { | |
| "raw": "{{baseUrl}}/protected", | |
| "host": [ | |
| "{{baseUrl}}" | |
| ], | |
| "path": [ | |
| "protected" | |
| ] | |
| } | |
| }, | |
| "response": [] | |
| } | |
| ], | |
| "variable": [ | |
| { | |
| "key": "baseUrl", | |
| "value": "http://localhost:3000" | |
| }, | |
| { | |
| "key": "jwtToken", | |
| "value": "" | |
| }, | |
| { | |
| "key": "userId", | |
| "value": "" | |
| } | |
| ] | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment