Saturday, December 3, 2016

Storage in ServiceWroker while site is not running


Few days back while working with service workers I got caught with a unique kind of problem. I wanted to show notification data to the users in a dropdown and the tricky part was the notifications sent  while site was not open in any tab. I was not able to store that information as service worker cant directly use DOM. As site was not open in any tab, it couldn't post it to the site JS which could have inserted it to localstorage.

Fortunately, I was able to solve the problem. As a workaround I tried a very tricky implementation. It was based on the fact that ServiceWorker specifications said it can not access DOM and it cannot store values in browser storage but it did not said anything about the global variables. So, I stored the values in global Variable just by declaring an array outside of all the methods.

var notificationList = new Array();

Parsed information of notification is then pushed to this list from the Event Listner where serviceworker is listening to push event.

notificationList.unshift(parsedNotificationData); 

Now this notification information is available and stored inside the serviceworker which webpage JS can ask for on load.

Hope this was a bit helpful.

Sunday, June 5, 2016

Unlocking user account in linux



Your account might get locked when you enter incorrect password a number of time while doing SSH login and that account will get unlocked only after a certain amount of time.

If you want to unlock the account quickly then you would require root (or sudo) access to the system. But first you have to understand the way it works.

There is module pam_tally2 which is used to lock user accounts after certain number of failed ssh login attempts made to the system. This module keeps the count of attempted accesses and too many failed attempts.

This pam_tally2 module comes in two parts, first is pam_tally2.so and another is pam_tally2. It is used to examine and manipulate the counter file. It can display user login attempts counts, set counts on individual basis and unlock all user counts.


You can see if any failed login attempts by firing following command:
 $pam_tally2
The output will be as below:


If you want to check failed login attempt for any specific user then use the command as

$pam_tally2 --user=<userId>
The output will be as below:
To unlock any account there can be multiple approaches. This article will demonstrate all those approaches.
1.       Via reset command
a.       Fire below mentioned command
$pam_tally2 --user=<userId> --reset
2.       Via editing the config file itself
a.       Fire below mentioned command
$vi /etc/pam.d/password-auth
b.      Look for line
auth        required      pam_tally2.so deny=3 onerr=fail unlock_time=1800
c.       You can modify each of the parameters mentioned in last past of the line
                                                               i.      Deny = this defines the number of wrong password attempts to lock an account
                                                             ii.      unlock_time = this defines the amount of time for which account should get locked. The time is in seconds
d.      After you modify parameters as per your need. Just save the file and try to login via locked account.

Hope above mentioned steps helped you.
























Monday, March 14, 2016

Choosing the right method for testing the mobile web app

Everyone is focusing more on their mobile web with the growing traffic from mobile devices and with that there is more focus on mobile testing. There are many techniques available in the market today to carry out activities on the mobile phone which are:

1.       Test Emulators – They will open up a device like environment right in your desktop system so that you can test without buying a real device. There are many such Emulators available in the market one the most famous is GenyMotion, Blue Stacks, etc
Cons:
a.       You might need high end system to run multiple devices side by side
b.      You might not able to simulate exact user behavior based on touch events

2.       Use chrome/Firefox in emulation mode – This involves opening up your desktop browser in the emulation mode so that it acts like a mobile web browser and send requests/response accordingly. You can refer to below mentioned links to know more about how to use the browsers in emulation mode.
Cons:
a.       Sometimes we cannot predict the behavior which might differ on the real devices
b.      Cannot simulate OS specific behaviors
3.       Use real devices: This is the best approach as nothing gives you more realistic results than a real device but accessing a test environment on a device is a really tricky thing to do, since whenever you hit a domain name on a device, it will take you to your production server unless you have done host mappings and editing host file on a device requires lots of steps to be done. There are other approaches available for the same and you can refer to my post for more details.
Cons:
a.       Costly way of doing testing