Friday, November 1, 2019

SonarQube setup on windows 10

Overview

SonarQube is an automatic code review tool to detect bugs, vulnerabilities and code smell in your code. It can integrate with your existing workflow to enable continuous code inspection across your project branches and pull requests. 

Prerequisite

Make sure you have JAVA 11 or higher version installed on your window machine.


Step to setup SonarQube

  • Download Community edition from https://www.sonarqube.org/downloads/
  • Extract it and go to the bin folder.
  • Choose windows-x86–32 or windows-x86–64 based on your machine configuration.
  • Run StartSonar.bat which will start the SonarQube server. 
  • Open browser and hit http://localhost:9000

  • If you want, you can start the sonarQube server to a different port by just updating the port number (sonar.web.port=9070) to sonar.properties which is present under conf directory.
  • You can login to the portal using default credential (admin:admin).

Congratulation! SonarQube server is up and running on localhost:9000.

Saturday, October 12, 2019

Postman API – Tips and Tricks

I have seen many people using POSTMAN tools but very few of them know how to exactly use all the features of POSTMAN application. So, in this article, I am going to share a few tips/tricks which can be really helpful in our API testing.

  • Set Environment Variables


Let’s assume we have an endpoint to get some data after authenticating yourself bypassing username/password.

Now, you have to test this endpoint which is deployed on multiple environments like a local machine, test environment and on SIT environment as well. Also, the credential is different for each environment.

So, how are we going to test it?

Most of the time, I have seen that people create one-one requests for each environment or create one request and then modify the existing username/password and hostname to point to a different environment.

The Simple Solution is to set changing parameters as an Environment variable and switch environment to test for different regions.

E.g. http://<HOSTNAME:POST>/token and <username>/<password> as basic Authentication 


How to set environment variables?

  • Click "Manage Environments" icon in the upper right corner of the Postman app.
  • Click the Add button.
  • Click "Environment" and enter a name for the new environment.
  • Add the variables you want to save as key-value pairs.
  • Click the Add button.





Selecting an active environment

  • Click the dropdown menu in the upper right corner of the Postman app to select an active environment, or type in the environment name.
  • Once you select an environment, you can access variables in the active environment scope.

All the parameters get changed as we switch from one environment to another one.

  • Set Global variable


Global variables provide a set of variables that are available in all scopes. You can have multiple environments, but only one environment can be active at a time with one set of global variables.

To manage global variables, click the gear icon in the upper right corner of the Postman app and select "Manage Environments".

Click the Globals button at the bottom of the modal to bring up a key-value editor to add, edit, and delete global variables.




 

  • Set Response to the global variable


There are so many scenarios where we wanted to add one of the API responses as a request parameter to the second request like getting token from one API and then passing this token to another endpoint to access the resources.

Assuming, I am hitting API to get access token and then setting access-token as a global variable. 




  • Once you get the access_token in your response then go to Tests tab.
  • Click on ‘set a global variable’ or add scripts as shown below
    • let response = pm.response.json();
    • pm.globals.set("access_token", response.access_token);
  • To access this variable in some other request, just pass the access_token parameter as {{access_token}} as we have done something similar for dev_hostname.
E.g. 


  • How to pass the path variable dynamically

I guess this is one of the major mistakes I have seen people doing it i.e. passing hardcoded path variable in the URL request

The below diagram will show you the correct way of passing it. Using this, you can update params value very easily.

http://hostname/users/:userId

To edit the path variable, click on Params to see it already entered as the key. Update the value as needed.



  • Save custom headers

You can save commonly used headers together in a header preset. Under the Headers tab, you can add a header preset to your request when you select "Manage Presets" from the Presets dropdown on the right. 





  • Check all request/response send to API

Goto View-> Show Postman Console



Sunday, September 8, 2019

Spring Boot Tutorial

Prerequisite: Basic knowledge of Spring boot application

I am working on a series of implementing frameworks with Spring boot application but not getting enough time to blog it and post it here or on my LinkedIn profile.

So, I have started uploading my work on my GitHub repository from where it can be downloaded easily. I tried my best to add short notes for each annotation/configuration/properties in README and even I have uploaded a few screenshots to understand in a more better way.

Try it out and Please do let me know in case of any confusion.
  1. Spring Boot Actuator
  2. Spring Boot Ehcache
  3. Spring Boot Swagger
  4. Spring Boot JPA

Will keep uploading with others framework as well.

Feedback is also most welcome.

Thank you.
Happy Learning!

How TOPT Works: Generating OTPs Without Internet Connection

Introduction Have you ever wondered how authentication apps like RSA Authenticator generate One-Time Passwords (OTPs) without requiring an i...