Tuesday, October 8, 2013

Domain name history search tool - found a non-paid one!

Hi there,
I was fighting the DNS system recently, and GoDaddy to name. Issue was that I was changing the nameservers for a given domain name, but for some reason GoDaddy disallowed to forward that domain. This worked out pretty well afterwards (just takes some time to wait).
However I made a mistake then. I have changed the NS servers, without writing down the old ones. When the change was done, I was unable to recover original IP of the service I was moving (oh sh!).
That was a moment of panic, however, after some searching I have come across (a finally free!) tool, which shows the history of the domain name change over time.
That’s http://whoisrequest.org/history/, and it works just perfectly. Using it, I was able to find out the historical NS records, and then query it for the old IP and it was relief :)

Friday, October 4, 2013

Setting up TeamCity coverage report for node.js test with mocha and jscoverage

Hi!

The mentioned tech stack has been popular for quite a while, leading to many people using it (especially in startups, for quick and robust API implementations, etc.). The question of testing is solved quite well (there is a number of testing, mocking, assert frameworks out there which I find astonishing).

This post is about quite a regular task on how to setup coverage metrics automatically on the build server (TeamCity is my favourite).

Disclaimer: I have a strong belief that coverage metrics should never be given to the business people w/out tech control. When they see _any_ metrics, they become excited with it and we have that overused. I believe, that coverage should be used by developers themselves to see what code paths have not been tested, and what tests can they add.


So, let's start. Prerequisites:

  1. You have mocha tests
  2. You have a working installation of TeamCity, which is already pulling the sources from repo, building app, running these tests on post-commit basis (and surely sends notifications to the people in charge).
  3. You want to add coverage metrics to the party to see what's the progress and what areas need more help. 
Given that your project structure knows nothing of jscoverage, we'll go least-intrusive, scripting way. 

Jscoverage

You need a specific jsCoverage build, which knows about node. You can have that installed, as usual, with npm:
 
npm install -g jscoverage

Verify the install, by issuing jscoverage on the commandline. The output is not very helpful, but gives the most interesting parameters you'll need. 

The way all coverage tools work is that either instrument the product of your code (or code itself, for scripting tools), OR plug into the interpreter, and when you apply some interaction to this code (tests, users coming in and out, etc), collect how many times each of the lines was called. After these numbers are obtained, static analysis may plug in to verify how many functions/branches/conditions were covered. 

So, we need to obtain such an 'instrumented' code first from our target code. That's what jscoverage doing:


jscoverage --exclude tests,node_modules,.git,target,.idea  CURRENT_FOLDER OUTPUT_FOLDER

After that you can examine the results in the output folder. All your files should be copied there (except the ones included), and they should have some weird code inside (that's the recording part!), with pieces and bits of your code scattered across the file. 

mocha

As you are already probably using mocha for testing, nothing is really tough here. I assume that you are loading your modules-under-test with the require('../../lib/something'), rather than via absolute paths. 

As we already have a specific folder, which contains jscoverage-processed main app code, w/out all the unnecessary folders, we could now just copy out the tests themselves to that folder, and run mocha. No results yet, we just verify that mocha tests run with our processed code. 

Next, we are good to go to add some html-cov reporting. This reporter is already bundled with mocha, so no need to reference it in package.json. what it does, is that after the mocha tests are ran, it gets the coverage statistics from coverage-augmented files under test, and flushes that (in form of HTML) to the stdout. So, to see what's in the coverage, we do (whilst in the OUTPUT_FOLDER): 

../.././node_modules/mocha/bin/mocha -t 20000 --noinject --reporter html-cov --recursive ./tests/ --coverage

--noinject is required for me, as I am using rewire library for testing, and that somehow clashes with the jscoverage stuff.

You could divert that output to file, or just pipe to w3m.

TeamCity

Quite an easy part now; since we have all working locally on the server, we just need to automate it. I have finally used a html-file-cov mocha reporter, it prints out the tests results as dots to the stdout, and writes the coverage report to coverage.html within working folder; quite an easy and handy tool.  https://npmjs.org/package/html-file-cov

In teamcity, we need to add another build step to the post-commit configuration. I did the easy and ugly script way instead of built-in report processing, since I was quite happy with the html format. 

So, as we have added that build step (of type Custom script), we could now fill it with the actual logic: 

#!/bin/bash

rm -rf ../target-cov/*
rm -rf ./target/target-cov
rm -rf ./target/coverage.html

mkdir -p ../target-cov
jscoverage --exclude tests,node_modules,.git,target,.idea . ../target-cov

mv ../target-cov ./target
cp -r ./tests ./target/target-cov
echo "JS files instrumented correctly"

cd target/target-cov
echo "Running mocha tests with 'dot' reporter"
NODE_ENV=dev ../.././node_modules/mocha/bin/mocha -t 20000 --noinject --reporter html-file-cov --recursive ./tests/ --coverage
mv ./coverage.html ..
echo "Done. Configuration stored to `pwd`/../coverage.html"


As a result of this manipulation (making a dir one level up, storing there the jscoverage-processed files, copying it to the local 'target' folder, copying over the tests non-processed, running the tests, moving the coverage.html to the target dir), we have the artifact - coverage.html - which contains all the stuff we need. 

We just need to publish it - in TeamCity project settings, on the very first page, there's an 'Artifacts' box, which takes paths. Just add +:target/coverage.html, and after each build you'll have a nice drop-down 'Artifacts' with a link to your html with coverage. 

Voila! 
 

Wednesday, March 13, 2013

Portecle - nice tool to manage certificates, keystores, keys, etc. Instead of keytool (jdk)

I was using keytool from jdk installation always. However, when it came down to bouncycastle implementation, too much work should be done to make it running - download a crypto provider, install it, etc. That's the description: http://stackoverflow.com/questions/4065379/how-to-create-a-bks-bouncycastle-format-java-keystore-that-contains-a-client-c

As Android uses bouncycastle by default, had to pack a public key of the RSA pair to the BKS store to make a resilient HttpsUrlConnection.

Found it very nice and handy to use http://portecle.sourceforge.net/ as a GUI tool.

Works flawlessly, recommended

Tuesday, March 12, 2013

Linux/mac alternative to Fiddler - WebScarab!

I really enjoy using fiddler - that is web logging proxy, or, the way it is called - a web debugger.

It works very easy way:

  1. When started, modifies the Internet Explorer proxy settings to point them on  itself.
  2. All the request are logged and ready to be analyzed then. 
  3. As much of the software does use IE proxy settings for its own setup, non-straightforward things as SOAP calls, Ajax, embedded-browser calls may also be caught. 
  4. With the captured interchange, one can analyze every aspect of a single roundtrip.
The only thing I dislike about it is its nature - .Net built, it works flawlessly on MS platform, but not on Linux.

The good and working alternative I have found is webscarab project, which is written in java, looks pretty much the same, and does most of the same job. Easy thing. Just run it with java-jar and setup your software to proxy through 127.0.0.1:8008.

Monday, March 11, 2013

Web-harvest scrapper 2.1 - how to use

Often it happens that you need to get some data from a web source, but the developers of the site disallow or simply do not have resources to implement any b2b API.

That's where scrapers come in. They are software pieces acting as a browser but providing some programmatic API to process results in a program code.

During my search for an acceptable solution, I came over the http://web-harvest.sourceforge.net/ ; nice features are:

  1. All-java, used as a library
  2. Great versatility - it is packed; really. Xquery, Xpath, regex searches, emulation of browser activity, templating and variables, different script integration. 
  3. Nice UI workbench, which allows to develop scripts easily and see the results immediately. Then, just save the XML configuration and invoke it from the code then. 
However, the version under link above is 2.0 version. It is not present in Maven, and I am building with maven. However, there is a new 2.1 version, which is highly redone - maven build process, switched to Guice injection, etc. 

I fancy 2.1 alot, but there are some issues with it - NO documentation at all, a little different behavior. I made a fork for myself on GitHub (https://github.com/lexaux/web-harvest) - and applying changes there. Hopefully, will be able to contact developers and contribute. 

For now, a quick how-to on running the 2.1 web-harvest scraper in your code (UI is pretty straightforward). It is really different from 2.0. So, here it goes: