Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9e9027d
Showing
9 changed files
with
204 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
Copyright (c) 2012, Nathaniel Ritmeyer | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
|
||
1. Redistributions of source code must retain the above copyright notice, | ||
this list of conditions and the following disclaimer. | ||
|
||
2. Redistributions in binary form must reproduce the above copyright | ||
notice, this list of conditions and the following disclaimer in the | ||
documentation and/or other materials provided with the distribution. | ||
|
||
3. Neither the name Nathaniel Ritmeyer nor the names of contributors to | ||
this software may be used to endorse or promote products derived from this | ||
software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS | ||
IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR | ||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | ||
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | ||
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | ||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
# Test Automation Firefox Password Manager | ||
|
||
A very basic Firefox plugin that allows updating the Password Manager at | ||
runtime using Javascript. When used in concert with the AuthoAuth | ||
plugin (https://addons.mozilla.org/en-US/firefox/addon/autoauth/ ), | ||
ActiveDirectory authentication dialogs will no longer cause your | ||
tests to fail. | ||
|
||
## Why it's awesome | ||
|
||
Until this plugin arrived, it has been impossible to dynamically add | ||
passwords to Firefox's Password Manager at runtime. This prevents using | ||
Firefox for testing websites that authenticate against ActiveDirectory. | ||
There are work arounds (as documented here: http://watirmelon.com/2012/06/27/automatic-firefox-authentication-when-using-selenium-webdriver-with-autoauth/ ) but you are then stuck with the burden of having to maintain | ||
a Firefox profile. Now, instead, you can go back to using dynamically | ||
created profiles at runtime and by calling a simple javascript function | ||
you can add as many host/username/password combinations as you like. | ||
|
||
## Why it's rubbish | ||
|
||
Javascript can only be injected and executed into a page that has already | ||
been loaded. This is frustrating because you can only update the Password | ||
Manager once the first page has loaded. The implications of this are | ||
that you need to first navigate to a page that doesn't present a | ||
password prompt, update the Password Manager from that page and only | ||
then should you navigate to the page that presents the password prompt. | ||
I'd love for someone to replace this plugin with something that doesn't | ||
require this extra step. | ||
|
||
## How to use it | ||
|
||
(NB: the following examples demonstrate how to use this plugin | ||
with capybara and ruby but the principles should carry across to | ||
anything else that can inject javascript into Firefox at runtime) | ||
|
||
### Download the plugins | ||
|
||
First, you'll need to download the test-automation-password-manager.xpi | ||
file from this repo, and you'll also need to download the latest | ||
AutoAuth plugin file (autoauth-2.1-fx+fn.xpi at time of writing) from | ||
https://addons.mozilla.org/en-US/firefox/addon/autoauth/ . Add both of | ||
them to a directory in your test project called `ff_plugins`. | ||
|
||
### Add the plugins to a dynamically created Firefox profile | ||
|
||
When you create your Firefox Profile at runtime, you'll need to add this | ||
plugin and the AutoAuth plugin: | ||
|
||
```ruby | ||
Capybara.register_driver :selenium_firefox do |app| | ||
#create the profile: | ||
profile = Selenium::WebDriver::Firefox::Profile.new | ||
#add the 2 plugins | ||
profile.add_extension(File.expand_path("ff_plugins/autoauth-2.1-fx+fn.xpi")) | ||
profile.add_extension(File.expand_path("ff_plugins/test-automation-password-manager.xpi")) | ||
|
||
Capybara::Selenium::Driver.new(app, :browser => :firefox, :profile => profile) | ||
end | ||
``` | ||
|
||
### Update Password Manager | ||
|
||
The following code shows how to add details to the Password Manager at | ||
runtime: | ||
|
||
```ruby | ||
#navigate to a page that won't prompt you for a password: | ||
|
||
visit 'http://www.google.com' | ||
|
||
#create the javascript that will send the relevant details to the password manager: | ||
|
||
pass_man_update_script = <<-SCRIPT | ||
var addCredentialsEvent = new CustomEvent("add_credentials_to_passman", { | ||
detail: { | ||
host: 'http://secure.example.com', | ||
username: 'bob', | ||
password: 'P45sword' | ||
} | ||
}); | ||
window.dispatchEvent(addCredentialsEvent); | ||
SCRIPT | ||
|
||
#inject the script into the browser: | ||
|
||
page.execute_script pass_man_update_script | ||
|
||
#navigate to the page that prompts you for a password: | ||
|
||
visit 'http://super_secure.example.com' | ||
#This used to present a password dialog that would cause the test to | ||
#fail, but now it doesn't! Woo! | ||
``` | ||
|
||
## Disclaimer | ||
|
||
* I am not a javascript dev | ||
* I am not a Firefox Addon dev | ||
* I only tested this against my current set up as I don't have anything | ||
else to test it against | ||
|
||
Please feel free to send me pull requests, or even better, make a better | ||
version of this plugin. The sooner I can retire this, the happier I'll be. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
window.addEventListener('add_credentials_to_passman', function(event) { | ||
self.port.emit('add_credentials_to_passman', event.detail); | ||
}, false); | ||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
const passwords = require("passwords"); | ||
const prefs = require("preferences-service"); | ||
const urls = require("url"); | ||
const data = require("self").data; | ||
|
||
var test_automation_password_manager = { | ||
add_credentials : function(url, username, password) { | ||
passwords.store({ | ||
url: url, | ||
realm: url, | ||
username: username, | ||
password: password, | ||
onError: function onError(error) { | ||
if(error.message.indexOf("This login already exists") == -1) { | ||
console.log(error.message) | ||
} | ||
} | ||
}); | ||
var url_host = urls.URL(url).host; | ||
this.add_trusted_uri(url_host); | ||
}, | ||
|
||
add_trusted_uri : function(trusted_uri) { | ||
var trusted_uris_prefs_name = "network.automatic-ntlm-auth.trusted-uris"; | ||
var original_trusted_uris = ""; | ||
if(prefs.isSet(trusted_uris_prefs_name)) { | ||
original_trusted_uris = prefs.get(trusted_uris_prefs_name) + ","; | ||
} | ||
var trusted_uris = original_trusted_uris + trusted_uri; | ||
prefs.set(trusted_uris_prefs_name, trusted_uris); | ||
}, | ||
}; | ||
|
||
var pageMod = require('page-mod').PageMod({ | ||
include: ['*'], | ||
contentScriptFile: data.url("content_script.js"), | ||
onAttach: function(worker) { | ||
worker.port.on('add_credentials_to_passman', function(message) { | ||
test_automation_password_manager.add_credentials(message.host, message.username, message.password); | ||
}); | ||
} | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"name": "test-automation-password-manager", | ||
"license": "BSD", | ||
"author": "Nat Ritmeyer", | ||
"version": "0.1", | ||
"fullName": "test-automation-password-manager", | ||
"id": "jid1-RBSCJoXkcndNCw", | ||
"description": "Inject credentials into the password manager at runtime using JS" | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "test-automation-password-manager", | ||
"fullName": "test-automation-password-manager", | ||
"description": "a basic add-on", | ||
"author": "", | ||
"license": "MPL 2.0", | ||
"version": "0.1" | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
var main = require("main"); | ||
|
||
exports.test_run = function(test) { | ||
test.pass("Unit test running!"); | ||
}; | ||
|