Wednesday, August 05, 2009

Unpacking Packed Javascript

You ever try to learn a new trick from a web page by looking at the source, only to discover code that looks like this?

eval(function(p,a,c,k,e,d){e=function(c){return(c<a?'':e(parseInt(c ….

That’s been “packed” (note the parameters to the function?) specifically so you can’t read the source.

It’s also easy to get around.  The browser at one point or another has to unpack it to run it, so what you need to do is catch it someplace where you can display it.

Copy your ugly packed code, and open up Firefox’s Error Console. 

Paste the packed code into the “Code” text box.

At the front of the string add the text   “eval=alert;” and then click Evaluate. 

This should bring up an alert box containing your unpacked code.

It’s such a pain in the neck, in fact, that there are also plenty of online tools that will go ahead and just do it for you.

Tuesday, August 04, 2009

Testing with Rails : Can I Test External / Outside Apps?

Most of our application is written in PHP, and not likely to be rewritten anytime soon (though that is a different topic).  However I’m well aware that this doesn’t have to stop the introduction of Ruby on Rails into the mix.  Our newest push for enhanced quality, testing and metrics gives me an idea:  Can I use the latest and greatest testing tools like Cucumber and RSpec to build up a test suite to run against our existing application?  I particularly like the idea of having a business language for test cases so I can write things like this:

Feature : Have a pleasant and useful homepage

In order to navigate around the site easily

As a Guest

I want to see useful links in the navigation menu

Scenario : Main Menu

Given I’m on the homepage

And I am not logged in

Then I should see a link called “Member Login”

And I should see a link called “Register”

And I should not see a link called “My Account”

That works for me.  I could write bunches and bunches of those.  (It may help that I’m an old natural language guy who’s always had a soft spot for such interfaces.)

However, the natural behavior of Cucumber if I’m doing it right is to assume that “homepage” is a route into the existing Rails app, and that’s not what I want.  I actually want it to map to my production site, complete with http://www.mysite.com syntax.

I found this link from Erik On Rails that talks about creating a new Mechanize session.  But when I do that, my next statement (“should see”) fails because it thinks I got nil content back from the visit to my url.

Is it supposed to be this hard?  I see a whole bunch of articles about using these tools to do what sounds like the same thing I want (i.e. testing something other than a native Rails app) but I can’t seem to find the answer to my question.  Can I hit an external, fully defined url, get back the content, and crawl/test that content?  How??