Last active
January 3, 2019 12:03
-
-
Save gunesmes/a3e7fa10928cd1122b62f6c87e4da2e6 to your computer and use it in GitHub Desktop.
postman
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
FROM node:6.5.0-slim | |
RUN npm install newman | |
RUN npm install newman-reporter-html | |
RUN mkdir /newman | |
WORKDIR /newman | |
ENTRYPOINT ["/node_modules/.bin/newman"] |
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
// If you need to RSA Ecryption for secure process, postman doesn't have embed library to use | |
// however you use pre-request script to encrpt your data over external services and create a environment variable | |
// this is an example for using https://8gwifi.org, better to use internal services. | |
var myData = {"name": "TestName","birthday": 03,"birthMonth": 09, "secret": "topSecretPassword"} | |
var encodedMyData = encodeURIComponent(JSON.stringify(myData)); | |
var encodedPublicKey = encodeURIComponent(pm.environment.get("puclic-key")); | |
var bodyEncodedMyData = `methodName=CALCULATE_RSA&encryptdecryptparameter=encrypt&publickeyparam=-----BEGIN+PUBLIC+KEY-----%0D%0A${encodedPublicKey}%0D%0A-----END+PUBLIC+KEY-----%0D%0A&privatekeyparam=&message=${encodedMyData}&cipherparameter=RSA`; | |
function setEncriptedData(encodedBody, envVariable) { | |
var options = { | |
url: 'https://8gwifi.org/RSAFunctionality', | |
method: 'POST', | |
header: { | |
'Postman-Token': 'd2bb585d-143f-478b-a072-9cb11d3c3eaf', | |
'cache-control': 'no-cache', | |
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', | |
Referer: 'https://8gwifi.org/RSAFunctionality?keysize=2048', | |
Connection: 'keep-alive', | |
Cookie: '_ga=GA1.2.1251699220.1541508658; __sharethis_cookie_test__; _gid=GA1.2.866230832.1544185166; JSESSIONID=0938492033A794B5FD2B9B48C1FA2351; __unam=78e6377-166e9136b28-4fee9eaa-19; sc_is_visitor_unique=rx9638240.1544186542.009BD77CC6D74F344498D05DECA1D5B2.6.6.6.6.6.5.4.3.3', | |
'X-Requested-With': 'XMLHttpRequest', | |
'Cache-Control': 'no-cache', | |
Accept: '*/*', | |
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36', | |
'Accept-Language': 'en-US,en;q=0.9,tr;q=0.8', | |
'Accept-Encoding': 'gzip, deflate, br', | |
Origin: 'https://8gwifi.org', | |
Pragma: 'no-cache' | |
}, | |
body: encodedBody | |
}; | |
var data = pm.sendRequest(options, function(err, res) { | |
responseHTML = cheerio(res.stream.toString()); | |
pm.environment.set(envVariable, responseHTML[0]["next"]["next"]["children"][0]["data"]); | |
}); | |
} | |
setEncriptedData(bodyEncodedMyData, "encryptedMyData"); |
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
~/P/p/m/service-test (master ⚡☡+) bash restore_db.sh | |
# * * * * * * RESTORE DATA STARTED * * * * * * | |
# DELETE ALL THE RECORDS IN THE FOLLOWING TABLE | |
TRUNCATE TABLE | |
ALTER SEQUENCE | |
# ADD TWO TEST USER TO src_users | |
INSERT 0 1 | |
INSERT 0 1 | |
# * * * * * * RESTORE DATA FINISHED * * * * * * | |
~/P/p/m/service-test (master ⚡☡+) newman run blog-sample-service.postman_collection.json -e blog-local.postman_environment.json --reporters cli,html --reporter-html-template report-template.hbs | |
newman | |
blog-sample-service | |
→ ping | |
GET localhost:8001/api/ping [200 OK, 166B, 33ms] | |
✓ Status code is 200 | |
✓ Body matches string to 'pong' | |
→ get-users | |
GET localhost:8001/api/users [200 OK, 545B, 20ms] | |
✓ Status code is 200 | |
✓ Number of users should be equal to 2 | |
✓ First user's information should be correct | |
✓ Second user's information should be correct | |
→ register-user-success | |
POST localhost:8001/api/register [201 Created, 252B, 22ms] | |
✓ Status code should be 201 | |
✓ Result should be true | |
✓ Message should be correct | |
→ register-user-fail-already-member | |
POST localhost:8001/api/register [202 Accepted, 237B, 17ms] | |
✓ Status code should be 202 | |
✓ Result should be true | |
✓ Message should be correct | |
→ register-user-fail-empty-username | |
POST localhost:8001/api/register [202 Accepted, 242B, 13ms] | |
✓ Status code should be 202 | |
✓ Result should be true | |
✓ Message should be correct | |
→ register-user-fail-empty-email | |
POST localhost:8001/api/register [202 Accepted, 242B, 13ms] | |
✓ Status code should be 202 | |
✓ Result should be true | |
✓ Message should be correct | |
→ register-user-fail-empty-birthday | |
POST localhost:8001/api/register [202 Accepted, 242B, 10ms] | |
✓ Status code should be 202 | |
✓ Result should be true | |
✓ Message should be correct | |
→ register-user-fail-empty-address | |
POST localhost:8001/api/register [202 Accepted, 242B, 29ms] | |
✓ Status code should be 202 | |
✓ Result should be true | |
✓ Message should be correct | |
→ register-user-fail-worng-format-birthday | |
POST localhost:8001/api/register [202 Accepted, 299B, 14ms] | |
✓ Status code should be 202 | |
✓ Result should be true | |
✓ Message should be correct | |
┌─────────────────────────┬──────────┬──────────┐ | |
│ │ executed │ failed │ | |
├─────────────────────────┼──────────┼──────────┤ | |
│ iterations │ 1 │ 0 │ | |
├─────────────────────────┼──────────┼──────────┤ | |
│ requests │ 9 │ 0 │ | |
├─────────────────────────┼──────────┼──────────┤ | |
│ test-scripts │ 9 │ 0 │ | |
├─────────────────────────┼──────────┼──────────┤ | |
│ prerequest-scripts │ 0 │ 0 │ | |
├─────────────────────────┼──────────┼──────────┤ | |
│ assertions │ 27 │ 0 │ | |
├─────────────────────────┴──────────┴──────────┤ | |
│ total run duration: 426ms │ | |
├───────────────────────────────────────────────┤ | |
│ total data received: 862B (approx) │ | |
├───────────────────────────────────────────────┤ | |
│ average response time: 19ms │ | |
└───────────────────────────────────────────────┘ |
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
// payment/payment-processing > test section | |
// payment processing request calls itself until the response is `processing` | |
// when get other response it should call the `payment/payment-complete` as `setNextRequest` | |
var jsonData = pm.response.json(); | |
if (jsonData.status == "processing"){ | |
// wait 1 second and re-try until the response status is successful | |
setTimeout(function(){}, 1000); | |
postman.setNextRequest("payment/payment-processing"); | |
} else { | |
pm.test("Successful POST request", function () { | |
pm.expect(pm.response.code).to.be.oneOf([200]); | |
}); | |
// after successful status, we should see complete status so call the next request | |
postman.setNextRequest("payment/payment-complete"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment