Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Testing with sensitive information

by rpanman (Scribe)
on Jul 09, 2007 at 18:18 UTC ( [id://625676]=perlquestion: print w/replies, xml ) Need Help??

rpanman has asked for the wisdom of the Perl Monks concerning the following question:

Greetings Monks,

I am currently writing a banking module to account details from an online bank account and, like a good monk, I am writing unit tests to ensure that my code is sane. However this has led me to a problem - obviously to test the basic functionality (e.g. getting my account balance) I need to put in my secure banking details. At the moment I have hardcoded this into the test but I want to move away from this since it could mean that I accidentally bundle up my account number etc and then post it on CPAN...

My alternatives appear to be:
1) Set environment variables with my secure information and access these from my test - so there's no danger of the info appearing on CPAN.

2) Emulate the bank's server using some kind of mock object and then just use dummy account info etc. This would mean that the tests could be run on anyone's system. However if the bank's interface changes then I would miss it, because my test would still pass.

3) Somehow run interactive tests to prompt the user for info. This feels like "bad form"...

Any opinions or tips gratefully received.

Replies are listed 'Best First'.
Re: Testing with sensitive information
by Corion (Patriarch) on Jul 09, 2007 at 18:25 UTC

    I'm the author of Finance::Banking::Postbank_de, and in my module I test via two kinds:

    • Demo account - the smart folks at postbank.de have a demo account with a well-known account number and PIN, and I run live tests against that demo account
    • Saved HTML files - WWW::Mechanize, which I use, can easily load HTML files via file:// URLs or ->set_content(), and I use that to load some canned content into the useragent for running offline tests. This does not protect me against site changes but it makes testing some parsing far easier

    I consider interactive test suites as very bad form, especially as I'm running CPAN smoke tests from time to time...

      Thanks Corion.

      Sadly there's active demo (just a load of flash), so that options out :-(

      I like the thought of at least being able to check the parsing is correct using file though, I'll definitely include that.

      No worries about the interactive tests - I had a feeling there was bad karma associated and now it has been confirmed I will steer well away :-)
      Corion,
      I consider it bad form for any test suite to automatically assume it is ok to contact the internet let alone phone home. I also see the interactive is bad argument. The comprimise in my opinion is to prompt the user for input with a sane timeout automatically defaulting to "no".

      With that said, I was thinking that it might be good to have continuously updating saved HTML files. I really haven't thought this through but here is the general idea. You have code that periodically logs in and pulls down sample files that are scrubbed (if no demo account available). These files are then place in a public facing location that the test suite points to if the user decides live tests are preferred.

      Cheers - L~R

Re: Testing with sensitive information
by Old_Gray_Bear (Bishop) on Jul 09, 2007 at 19:49 UTC
    I am not building anything as sensitive as a Financial App, but I do to need to get User data from a remote Instant Messaging system's database.

    I built a set of testing accounts with known (to my test-package) passwords, and patterned user-data (for example, address1=user1-address1-xxxx, where xxxx is unique test-id (in reality the PID.time() at the start of the test sequence)). This is the only way that I could think of to

    • Reliably test the interface in the face of a shifting API (there is only one of me writing the test harness; there are thirty or forty folks in Engineering fixing bugs and extending the feature set)
    • Keep from leaking of my personal account and password data.

    The method of generating patterned data turned out to have a side-benefit, I don't have to keep re-initializing the dummy accounts with a known data-state. I can just leave the account in the updated state since I know that my next test run will generate a different test-id by virtue of the included time-stamp. I use the fact that the test-id is in the data to validate the test results (is the time-stamp different or the same? Is this what I expect?).

    A few years ago, I was working contract for one of the local banks in San Francisco (one with branches all over the state of California and elsewhere). There was a formal standard for building 'dummy' account-numbers, to we could 'test on the live system'.

    We had someone run a test on the Check Ordering software and 'forget' to cancel the order to the printer (Rocky Mountain Banknote, as I recall). When the checks were delivered, Someone started using them to pay for purchases at stores in the Los Angeles air-basin. Since the account did have a positive balance (no surprise here), the checks all cleared.

    The Bank didn't twig to the scam for over a month, until the quarterly account-reports came out and showed activity against a dummy account that didn't come from a test-id. They initially 'solved' the problem by sending instructions to all of their Printers to report 'suspicious' account numbers while they figured out a real solution. This generated a lot of false-positives....

    My contract expired seven months later, and they were still arguing about the best way to prevent the scam from happening again.

    UPDATE: added a paragraph tag after the list close; cleaned up the wording in the first sentence.

    ----
    I Go Back to Sleep, Now.

    OGB

      If only I could get one of those accounts :-)
Re: Testing with sensitive information
by Herkum (Parson) on Jul 10, 2007 at 00:03 UTC

    Depending on your code, take a look at Mock::Object and Mock::Module. The idea is to override what every object/module that you use for getting and receiving data and force it to return something specific. This will separate the requests for data from module that manipulates the data.

Re: Testing with sensitive information
by graff (Chancellor) on Jul 10, 2007 at 03:16 UTC
    You might consider using a config file of some sort to store the username/password information. Then if, for whatever reason, you decide to put the module on CPAN, make sure that:
    1. Your own personal config file does not go into the distro
    2. There are clear instructions in the installation docs for the module that make it explicitly obvious to the people who install it that they must provide their own username/password info in the config file in order to run tests.

    But then, I think there's still a dilemma. Supposing I wanted to install your module in order to access my own personal bank account (assuming the unlikely possibility that I have an account at the same bank as you, so that everything should work as expected), I don't know how willing I would be to run tests to make sure the module works as intended, using my own bank account as the test bed.

    Somehow, that would seem like a bad idea, quite apart from the notion that my account information might be different enough from yours that it might be hard to anticipate what sorts of values and results should be expected.

    An ideal solution, similar to what DBI does, would be if the bank would support a "test user" account with stable and reliable data that would always return the same values for the test conditions (unless the tests were failing, of course). But I assume the likelihood of any bank doing that for the sake of a CPAN contributer is nil. So much for the ideal solution.

    All things considered, I don't think you can arrive at the appropriate "level of abstraction" to make this sort of thing viable as a CPAN package. You'll have enough to worry about just making sure it continues to work as intended for your own personal needs (as the bank "improves" its presentation strategies), so let that be sufficient.

    (You asked for opinions; that's mine.)

      Good point about using your own bank account as the test bed... I hadn't really considered the users' perspective (schoolboy error). I've made the test an author test anyway so it shouldn't run for other users unless they explicitly ask for it.

      The config file is a tidy idea, so I'll probably go with that for now.

      As you say, absolutely no chance of getting a test account with the bank :-(
Re: Testing with sensitive information
by exussum0 (Vicar) on Jul 10, 2007 at 17:22 UTC
    However this has led me to a problem - obviously to test the basic functionality (e.g. getting my account balance) I need to put in my secure banking details
    You're doing end-to-end testing and unit testing at the same time it sounds.

    Don't do that. Distribute your unit tests. They show patterns of use of the API you are writing.

    Keep your end-to-end tests closest to your QA group (yourself likely). They are more brittle, unlike unit tests. Unit tests are small, discrete. end-to-end layers your unit tests in ways that can break when integrated, lack a perfect environment or are configured in odd ways.

    Persons w/ a large POV will value them more because they are more likely to find edge case bugs.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://625676]
Approved by Fletch
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2024-04-20 03:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found