Posts

Showing posts from 2017

Importing a self signed certificate to java cacert trust store

The following steps to be used only in non production environments. Self signed certificates could be used in some organisations to make server to server calls between java programs on SSL.  During these situations, we can import the certificate from the server jvm to client's jvm to fix the SSL handshake issue. On Server JVM: Generate a self signed certificate keytool -genkey -noprompt -alias test.example.com -dname "CN=localhost, OU=Team Name, O=Organisation Name, L=London, S=Greater London, C=UK" -ext "san=dns:test.example.com,dns:test.example.org" -storetype PKCS12 -keyalg RSA -keysize 2048 -keystore /tmp/keystore.p12 -validity 36500 -storepass mypassword -keypass mypassword List the certificate keytool -list -keystore /tmp/keystore.p12 -storepass mypassword -storetype PKCS12 -v Export the certificate keytool -exportcert -keystore /tmp/keystore.p12 -storetype PKCS12 -storepass mypassword -alias localhost -file /tmp/test.example.com.crt On...

Install a specific version of a package in Debian / Ubuntu

Quiet often we setup auto pipelines for Continuous Integration in Cloud (like GitLab CI, Travis CI etc) and we install required packages (like mvn or gradle) using apt-get install  command to run the build. Sometimes it is quiet important to have a specific major version of a package or major-minor version of a package to run the build, otherwise the build might break with unintended behaviour. Hence this post explains the following commands on Debian / Ubuntu operating system: List all available packages Search for a package List the available version of a package Install a specific version of a package Install a specific major version of a package Install a specific major.minor version of a package Install a specific major.minor.security version of a package List all available packages apt-cache pkgnames Search for a package apt-cache search jdk List the available version of a package apt-cache madison maven Install a specific version of a package ...

Import self signed in Linux for Chrome / Chromium headless testing

Chrome / Chromium browser offers headless mode, which is quite useful to run tests via Selenium WebDriver in CI servers. However under some circumstance your test will hit a server with self signed certificate or invalid certificate or expired certificate. This may happen for developers trying to write tests against a server started on localhost with self signed certificates or testers trying to write tests against non-production servers with expired certificates (invalid certificates). Chrome / Chromium browser ignores the SSL errors when running in non-headless mode. However in CI servers, then it should be running in headless mode and currently we cannot ignore the SSL errors for tests accessing non-localhost websites. This blogs explains the steps for import a certificate into Linux's trust store, which will make the Chrome / Chromium browser to trust the self signed certificate.  Please do not apply these steps in production servers as it will make server vulnerable to ...

docker-compose plain ubuntu container

The following article explains how to start and keep running a plain ubuntu container in the background. During everyday software development, you might want to share a folder in host machine along with a unix based container like Debian or Ubuntu container to verify if certain things works as expected in headless mode or remote server. Hence this blog post explains how to start and keep running an empty Ubuntu container without installing any additional package or service and the current directory of host machine will be mounted at /var/host_machine_folder/ Create file "my-ubuntu-container.yml" with the following contents ################ services:   my-ubuntu:     container_name: my-ubuntu     image: "ubuntu:latest"     command: tail -f /dev/null     volumes:       - .:/var/host_machine_folder/     environment:       # This is set in host system and the value from host system ...

Maven change project version

Changing snapshot to release mvn versions:set -DoldVersion=1.0-SNAPSHOT -DnewVersion=1.0 -DgenerateBackupPoms=false Changing release to snapshot mvn versions:set -DoldVersion=1.0 -DnewVersion=2.0-SNAPSHOT -DgenerateBackupPoms=false

Maven Dependency Tree

Maven dependency tree mvn dependency:tree -Dverbose Maven dependency tree with filter mvn dependency:tree -Dverbose -Dincludes=org.testng:testng

tcpdump and wireshark

tcpdump and wireshark Capture traffic in a file using tcpdump: $ sudo tcpdump -i any -w /tmp/xxx.dmp -s 0 host localhost and port 8080 $ sudo tcpdump -i any -w /tmp/xxx.dmp -s 0 net 127.0.0.1 and port 8080 View traffic from dump file using wireshark: $ wireshark -r /tmp/xxx.dmp Optionaly apply filter in wireshark as "http" Click on a Http request On the bottom pane, right click on "eXtensible Markup Language" -> Copy -> Bytes -> Printable Text Only Paste the text in clipboard into a text editor

Simple Docker build example

Example of simple docker build and run This blog shows a very simple example of build a docker image and serve as http server using python. This also covers the concepts of environment variable, volumes and installing packages in building the docker image. Create Files Create the following two files with the contents below: Dockerfile ######################## FROM ubuntu:latest # Install python3 RUN apt-get update RUN apt-get install -y python3 # Set default values for environment variables ENV PORT 8080 # Copy Default Content COPY . /var/www/ # Change to working directory WORKDIR /var/www/ # Expose Ports EXPOSE $PORT # Run Http Server CMD python3 -m http.server $PORT ######################## sample-file.txt My Sample Content..... Build the image docker build --pull -t example/python-http-server:latest -f Dockerfile . Run the image as container docker run --rm -it --name my-python-http-server -p "808...

Docker Compose Hybrid

Docker Compose Hybrid (build + image) The following blog shows example of a hybrid docker-compose file which build an image and also runs a side container Create file "my-docker-compose-hybrid.yml" with the following contents ################ networks:   main:     name: my-docker-compose-network services:   my-python-simplehttpserver:     container_name: my-python-simplehttpserver     build: ./python-simplehttpserver     ports:       - "9080:8080"     volumes:       - .:/var/www/     networks:       main:         aliases:           - my-python-simplehttpserver   my-mongo:     container_name: my-mongo     image: "mongo:3.2"     ports:       - "27017:27017"     networks:       main:     ...

Docker Compose Basics

Running multiple containers using docker-compose Create my-docker-compose.yml  file  with the following contents: ################ networks:   main:     name: my-docker-compose-network services:   my-postgres:     container_name: my-postgres     image: "postgres:9.4.8"     ports:       - "5432:5432"     environment:       - "POSTGRES_USER=myuser"       - "POSTGRES_PASSWORD=superpassword"     networks:       main:         aliases:           - my-postgres   my-mongo:     container_name: my-mongo     image: "mongo:3.2"     ports:       - "27017:27017"     networks:       main:         aliases:           - my-mongo ################ ...

Git Basic Commands

Git Basic Commands Clone a repository git clone https://gitlab.com/someuser/my-test-repo.git Configure repository Set user.name git config user.name "someuser" Set user.email git config user.email some.user@example.org Set pull.rebase git config pull.rebase false Set push.default git config push.default simple Set credential cache For Unix/Linux Cache for 600 seconds git config credential.helper ‘cache --timeout=600’ For Mac OSX git config credential.helper osxkeychain For Windows git config credential.helper wincred Set core.longpaths (for windows) git config core.longpaths true Set http and https proxy git config http.proxy http.proxy http://proxyuser:proxypwd@proxy.server.com:8080 git config https.proxy http.proxy http://proxyuser:proxypwd@proxy.server.com:8080 Get http and https proxy git config --get http.proxy git config --get https.proxy Unset http and https proxy git config --unset http.proxy git config -...

Docker Client Basics

Docker Client Basics Run a bash shell in temporary Ubuntu Container and install packages docker run --pull=missing -it --rm ubuntu:latest /bin/bash or docker run --pull=missing -it --rm --entrypoint=/bin/bash ubuntu:latest or docker pull ubuntu:latest docker run -it --rm --entrypoint=/bin/bash ubuntu:latest apt-get update apt-get install curl -y exit Run a bash shell in already started container docker run --name ubuntu-latest -it --rm --entrypoint=/bin/bash ubuntu:latest docker exec -it ubuntu-latest /bin/bash Run a command in already started container in non-interactive mode docker run --name ubuntu-latest -it --rm --entrypoint=/bin/bash ubuntu:latest docker exec ubuntu-latest echo 'Hello World' Run a container in detached mode (-d) and see logs and stop the container docker run -d --rm --name keycloak-dev -p 8080:8080 quay.io/keycloak/keycloak:26.2.5 start-dev docker exec -it keycloak-dev /bin/bash docker logs --follow keycloak-dev docker stop keyclo...

Curl Basics

Curl Basics for testing Http Execute GET curl -X GET " https://www.example.org/ " Execute GET with encoded query parameters curl -X GET -G " https://www.example.org/ " --data-urlencode "query1=foo+bar" --data-urlencode "query2=my&special" --data-urlencode "query2=second&value" Execute POST curl -X POST " https://www.example.org/ " Ignore SSL Error curl --insecure -X GET " https://www.example.org/ " Use Http Proxy curl -X POST " https://www.example.org/ " --proxy "http[s]://[user:password@]proxyhost[:port]" Latency / Response time curl -X GET "https://www.example.org/" -s -o /dev/null -w 'Establish Connection: %{time_connect}s\nReceive First Byte: %{time_starttransfer}s\nTotal: %{time_total}s\n' Timeouts curl --max-time 5.5 --connect-timeout 2.5 "https://example.org/" --max-time is the total time to be spent in seconds --conne...