Socket
Socket
Sign inDemoInstall

firefox-profile

Package Overview
Dependencies
Maintainers
1
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

firefox-profile - npm Package Compare versions

Comparing version 0.0.3 to 0.1.1

.coveralls.yml

11

CHANGELOG.md

@@ -0,3 +1,14 @@

# 0.1.0
* more unit tests, added integration tests, saucelabs
# 0.0.4
* added addExtensions(array, callback) method
* EMFILE bug fix
* added basic tests for encoded()
# 0.0.3
* encoded is now asynchronous (adm-zip to node-archiver constraints to zip profile)

@@ -11,2 +11,3 @@ /

- <a name="toc_firefoxprofileprototypeaddextensionpath-callback"></a>[FirefoxProfile.prototype.addExtension](#firefoxprofileprototypeaddextensionpath-callback)
- <a name="toc_firefoxprofileprototypeaddextensionspath-callback"></a>[FirefoxProfile.prototype.addExtensions](#firefoxprofileprototypeaddextensionspath-callback)
- <a name="toc_firefoxprofileprototypeupdatepreferences"></a>[FirefoxProfile.prototype.updatePreferences](#firefoxprofileprototypeupdatepreferences)

@@ -66,2 +67,13 @@ - <a name="toc_firefoxprofileprototypepath"></a>[FirefoxProfile.prototype.path](#firefoxprofileprototypepath)

# FirefoxProfile.prototype.addExtensions(path, callback)
> Add mutliple extension to the profile.
**Parameters:**
- `{string} path` - path to a xpi extension file or a unziped extension folder
- `{function} callback` - the callback function to call when the extension is added
<sub>Go: [TOC](#tableofcontents) | [FirefoxProfile.prototype](#toc_firefoxprofileprototype)</sub>
# FirefoxProfile.prototype.updatePreferences()

@@ -68,0 +80,0 @@

54

Gruntfile.js
module.exports = function(grunt) {
'use strict';
grunt.loadNpmTasks('grunt-apidox');
grunt.loadNpmTasks('grunt-mocha-test');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-mocha-cov');
var coverallsRepoToken = process.env.COVERALLS_REPO_TOKEN,
coveralls = { serviceName: 'travis-ci' };
// for local run...
if (coverallsRepoToken) {
coveralls.repoToken = coverallsRepoToken;
}
grunt.initConfig({
mochaTest: {
test: {
mochacov: {
unit: {
options: {
reporter: 'spec',
// Require blanket wrapper here to instrument other required
// files on the fly.
//
// NB. We cannot require blanket directly as it
// detects that we are not running mocha cli and loads differently.
//
// NNB. As mocha is 'clever' enough to only run the tests once for
// each file the following coverage task does not actually run any
// tests which is why the coverage instrumentation has to be done here
require: 'coverage/config'
},
src: ['test/**/*.js']
reporter: 'spec'
}
},
coverage: {
reporter: 'html-cov',
// require: ['should']
output: './coverage/coverage.html'
},
coveralls: {
options: {
reporter: 'html-cov',
// use the quiet flag to suppress the mocha console output
quiet: true,
// specify a destination file to capture the mocha
// output (the quiet option does not suppress this)
captureFile: 'coverage/coverage.html'
},
src: ['test/**/*.js']
coveralls: coveralls
}
},
options: {
files: ['test/*.js', 'test/**/*.js']
}
},

@@ -44,3 +45,3 @@ apidox: {

files: ['**/*.js'],
tasks: ['mochaTest:test'],
tasks: ['mochacov'],
options: {

@@ -52,5 +53,6 @@ spawn: false,

});
grunt.registerTask('travis', ['mochacov:unit', 'mochacov:coveralls']);
grunt.registerTask('default', 'mochaTest:test');
grunt.registerTask('docs', 'apidox');
};

@@ -13,2 +13,5 @@ /**/

archiver = require('archiver'),
uuid = require('node-uuid'),
Readable = require('lazystream').Readable,
async = require('async'),
uuid = require('node-uuid');

@@ -91,3 +94,4 @@

function FirefoxProfile(profileDirectory) {
this.defaultPreferences = config.DEFAULT_PREFERENCES;
// cloning!
this.defaultPreferences = JSON.parse(JSON.stringify(config.DEFAULT_PREFERENCES));
this.profileDir = profileDirectory;

@@ -146,2 +150,21 @@ if (!this.profileDir) {

/**
* Add mutliple extension to the profile.
*
* @param {string} path - path to a xpi extension file or a unziped extension folder
* @param {function} callback - the callback function to call when the extension is added
*/
FirefoxProfile.prototype.addExtensions = function(extensions, cb) {
var self = this,
functions = extensions.map(function(extension) {
return function(callback) {
self.addExtension(extension, callback);
};
});
async.parallel(functions, cb);
};
/**
* Save user preferences to the user.js profile file.

@@ -167,3 +190,3 @@ *

FirefoxProfile.prototype.canAcceptUntrustedCerts = function () {
return this._santisePref(this.defaultPreferences['webdriver_accept_untrusted_certs']);
return this._sanitizePref(this.defaultPreferences['webdriver_accept_untrusted_certs']);
};

@@ -186,3 +209,3 @@

FirefoxProfile.prototype.canAssumeUntrustedCertIssuer = function () {
return this._santisePref(this.defaultPreferences['webdriver_assume_untrusted_issuer']);
return this._sanitizePref(this.defaultPreferences['webdriver_assume_untrusted_issuer']);
};

@@ -205,3 +228,3 @@

FirefoxProfile.prototype.nativeEventsEnabled = function () {
return this._santisePref(this.defaultPreferences['webdriver_enable_native_events']);
return this._sanitizePref(this.defaultPreferences['webdriver_enable_native_events']);
};

@@ -237,8 +260,10 @@

files.forEach(function(filePath) {
console.log('file in profile: ', filePath);
if (fs.statSync(path.join(self.profileDir, filePath)).isFile()) {
var srcStream = new Readable(function() {
return fs.createReadStream(path.join(self.profileDir, filePath));
});
archive.append(fs.createReadStream(path.join(self.profileDir, filePath)), { name: filePath });
archive.append(srcStream, { name: filePath });
}
});

@@ -250,6 +275,6 @@ archive.finalize();

var ffValues = {
'direct': 1,
'manual': 2,
'pac': 3,
'system': 4
'direct': 0,
'manual': 1,
'pac': 2,
'system': 3
};

@@ -267,8 +292,10 @@

if (!proxy || !proxy.proxyType) {
throw 'firefoxProfile: not a valid proxy type';
throw new Error('firefoxProfile: not a valid proxy type');
}
ffValues[proxy.proxyType] && this.setPreference('network.proxy.type', ffValues[proxy.proxyType]);
this.setPreference('network.proxy.type', ffValues[proxy.proxyType]);
switch (proxy.proxyType) {
case 'manual':
this.setPreference('network.proxy.no_proxies_on', proxy.noProxy);
if (proxy.noProxy) {
this.setPreference('network.proxy.no_proxies_on', proxy.noProxy);
}
this._setManualProxyPreference('ftp', proxy.ftpProxy);

@@ -280,3 +307,3 @@ this._setManualProxyPreference('http', proxy.httpProxy);

case 'pac':
this.setPreference('network.proxy.autoconfig_url', proxy.proxyAutoconfigUrl);
this.setPreference('network.proxy.autoconfig_url', proxy.autoconfigUrl);
break;

@@ -330,3 +357,3 @@

if (!addonId) {
throw 'FirefoxProfile: the addon id could not be found!';
throw new Error('FirefoxProfile: the addon id could not be found!');
}

@@ -361,3 +388,3 @@ var addonPath = path.join(self.extensionsDir, '/', addonId);

'version': null
};
}, self = this;

@@ -378,4 +405,4 @@ function getNamespaceId(doc, url) {

parseString(doc, function (err, doc) {
var em = getNamespaceId(doc, "http://www.mozilla.org/2004/em-rdf#"),
rdf = getNamespaceId(doc, "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
var em = getNamespaceId(doc, 'http://www.mozilla.org/2004/em-rdf#'),
rdf = getNamespaceId(doc, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#');
// first description

@@ -396,3 +423,4 @@ var rdfNode = unprefix(doc, 'RDF', rdf);

if (details[attr.replace(em + ':', '')] !== undefined) {
details[attr.replace(em + ':', '')] = description[attr][0];
// to convert boolean strings into booleans
details[attr.replace(em + ':', '')] = self._sanitizePref(description[attr][0]);
}

@@ -412,7 +440,7 @@

fs.mkdirSync(folderName);
//console.log('created folder: ', folderName);
// console.log('created folder: ', folderName);
return folderName;
};
FirefoxProfile.prototype._santisePref = function(val) {
FirefoxProfile.prototype._sanitizePref = function(val) {
if (val === 'true') {

@@ -422,3 +450,3 @@ return true;

if (val === 'false') {
return true;
return false;
}

@@ -431,3 +459,3 @@ else {

FirefoxProfile.prototype._setManualProxyPreference = function(key, setting) {
if (!setting || setting === '') {
if (!setting || setting === '') {
return;

@@ -434,0 +462,0 @@ }

{
"name": "firefox-profile",
"version": "0.0.3",
"description": "firefox profile for selenium WebDriverJs",
"version": "0.1.1",
"description": "firefox profile for selenium WebDriverJs, admc/wd or any other node selenium driver that supports capabilities",
"main": "lib/firefox_profile",

@@ -10,3 +10,8 @@ "directories": {

"scripts": {
"test": "mocha"
"test": "grunt travis",
"blanket": {
"pattern": [
"/lib/firefox_profile"
]
}
},

@@ -36,6 +41,8 @@ "repository": {

"grunt": "~0.4.1",
"grunt-mocha-test": "~0.7.0",
"blanket": "~1.1.5",
"grunt-contrib-watch": "~0.5.3",
"grunt-apidox": "~0.1.3"
"grunt-apidox": "~0.1.3",
"wd": "~0.2.0",
"chai-as-promised": "~4.1.0",
"grunt-mocha-cov": "0.0.7"
},

@@ -47,4 +54,6 @@ "dependencies": {

"node-uuid": "~1.4.1",
"archiver": "~0.4.10"
"archiver": "~0.4.10",
"lazystream": "~0.1.0",
"async": "~0.2.9"
}
}
# firefox-profile-js
[![Build Status](https://travis-ci.org/saadtazi/firefox-profile-js.png)](https://travis-ci.org/saadtazi/firefox-profile-js)
[![Coverage Status](https://coveralls.io/repos/saadtazi/firefox-profile-js/badge.png)](https://coveralls.io/r/saadtazi/firefox-profile-js)
[![Dependency Status](https://david-dm.org/saadtazi/firefox-profile-js.png)](https://david-dm.org/saadtazi/firefox-profile-js)
Firefox Profile for [Selenium WebdriverJS](https://code.google.com/p/selenium/wiki/WebDriverJs)
[![NPM](https://nodei.co/npm/firefox-profile.png)](https://nodei.co/npm/firefox-profile/)
Firefox Profile for [Selenium WebdriverJS](https://code.google.com/p/selenium/wiki/WebDriverJs),
[admc/wd](https://github.com/admc/wd) or any other library that allows you to set capabilities.
This class allows you to:

@@ -11,4 +16,7 @@

* use an existing profile (by specifying path)
* add extensions to your profile,
* specify proxy settings,
* set the user preferences...
You can add extensions to your profile, specify proxy settings, set the user preferences... More info on user preferences [here](http://kb.mozillazine.org/User.js_file).
More info on user preferences [here](http://kb.mozillazine.org/User.js_file).

@@ -37,2 +45,8 @@ ## Installation

```js
/******************************************************************
* with selenium webdriverJs
* installs firebug
* and make http://saadtazi.com the url that is opened on new tabs
/******************************************************************
var webdriver = require('selenium-webdriver');

@@ -43,5 +57,6 @@

var myProfile = new FirefoxProfile();
// add an extension by specifying the path to the xpi file or to the unzipped extension directory
myProfile.addExtension('./path/to/a/firefox/extension-file.xpi', function() {
// you can add an extension by specifying the path to the xpi file
// or to the unzipped extension directory
myProfile.addExtension('test/extensions/firebug-1.12.4-fx.xpi', function() {

@@ -51,6 +66,11 @@ var capabilities = webdriver.Capabilities.firefox();

// attach your newly created profile
myProfile.encoded(function(prof) {
capabilities.set('firefox_profile', myProfile.encoded());
myProfile.encoded(function(encodedProfile) {
capabilities.set('firefox_profile', encodedProfile);
// you can set firefox preferences
myProfile.setPreference('browser.newtab.url', 'http://saadtazi.com');
// required to create or update user.js
// it is required to create or update user.js
// only needed if you set some preferences
myProfile.updatePreferences();

@@ -66,7 +86,36 @@

});
});
/**************************************************
/* with admc/wd
/* installs firebug, and make it active by default
/**************************************************
var FirefoxProfile = require('./lib/firefox_profile'),
wd = require('wd');
// set some userPrefs if needed
var fp = new FirefoxProfile();
// activate and open firebug by default for all sites
fp.setPreference('extensions.firebug.allPagesActivation', 'on');
// activate the console panel
fp.setPreference('extensions.firebug.console.enableSites', true);
// show the console panel
fp.setPreference('extensions.firebug.defaultPanelName', 'console');
fp.updatePreferences();
// you can install multiple extensions at the same time
fp.addExtensions(['test/extensions/firebug-1.12.4-fx.xpi'], function() {
fp.encoded(function(zippedProfile) {
browser = wd.promiseChainRemote();
browser.init({
browserName:'firefox',
// set firefox_profile capabilities HERE!!!!
firefox_profile: zippedProfile
}).
// woOot!!
get('http://en.wikipedia.org');
});
});
```
## API Documentation

@@ -83,7 +132,7 @@

# or
grunt mochaTest:test
grunt mochacov:unit
## Coverage
grunt mochaTest:coverage
grunt mochacov:coverage

@@ -105,9 +154,4 @@ Generates doc/coverage.html

I currently only use the addExtension(), ~~I only quickly manually tested the user preference~~ I am in the process of ading more tests.
f.setPreference('browser.newtab.url', 'http://saadtazi.com');
f.updatePreferences();
## Found a bug?
Open a [github issue](https://github.com/saadtazi/firefox-profile-js/issues).
/*jshint camelcase:false*/
/*global describe:false, it:false, beforeEach:false*/
/*global describe:false, it:false, beforeEach:false, xit:false*/
'use strict';
var chai = require('chai'),
path = require('path'),
expect = chai.expect,
// sinon = require('sinon'),
FirefoxProfile = require('../lib/firefox_profile'),
fs = require('fs');
var chai = require('chai'),
path = require('path'),
expect = chai.expect,
FirefoxProfile = require('../lib/firefox_profile'),
fs = require('fs'),
testProfiles = require('./test_profiles')
// sinon = require('sinon'),
// sinonChai = require("sinon-chai")
;
chai.use(require('sinon-chai'));
// chai.use(require('sinon-chai'));
chai.use(require('chai-fs'));

@@ -24,3 +29,3 @@

it('with parameter, lock files should not be copied over', function() {
var fp = new FirefoxProfile(path.join(__dirname, 'empty-profile'));
var fp = new FirefoxProfile(testProfiles.emptyProfile.path);
expect(fp.profileDir.slice(-6)).to.be.equal('-copy/');

@@ -60,5 +65,50 @@ expect(fs.statSync(fp.profileDir).isDirectory()).to.be.true;

describe('#setProxy', function() {
it('should throw an expection if no proxyType is specified', function() {
var fp = new FirefoxProfile();
expect(function() {
fp.setProxy({httpProxy: 'http-proxy-server:8080'});
}).to.throw(Error);
});
it('should allow to set manual proxy', function() {
var fp = new FirefoxProfile();
fp.setProxy({
proxyType : 'manual',
noProxy : 'http://google.com, http://mail.google.com',
httpProxy : 'http-proxy-server:8080',
ftpProxy : 'ftp-proxy-server:2121',
sslProxy : 'ssl-proxy-server:4443',
socksProxy: 'socks-proxy-server:9999'
});
expect(fp.defaultPreferences).to.have.property('network.proxy.type', '1');
expect(fp.defaultPreferences).to.have.property('network.proxy.no_proxies_on', '"http://google.com, http://mail.google.com"');
expect(fp.defaultPreferences).to.have.property('network.proxy.http', '"http-proxy-server"');
expect(fp.defaultPreferences).to.have.property('network.proxy.http_port', '"8080"');
expect(fp.defaultPreferences).to.have.property('network.proxy.ftp', '"ftp-proxy-server"');
expect(fp.defaultPreferences).to.have.property('network.proxy.ftp_port', '"2121"');
expect(fp.defaultPreferences).to.have.property('network.proxy.ssl', '"ssl-proxy-server"');
expect(fp.defaultPreferences).to.have.property('network.proxy.ssl_port', '"4443"');
expect(fp.defaultPreferences).to.have.property('network.proxy.socks', '"socks-proxy-server"');
expect(fp.defaultPreferences).to.have.property('network.proxy.socks_port', '"9999"');
});
it('should allow to set auto-config proxy', function() {
var fp = new FirefoxProfile();
fp.setProxy({
proxyType : 'pac',
autoconfigUrl: 'http://url-to-proxy-auto-config'
});
expect(fp.defaultPreferences).to.have.property('network.proxy.type', '2');
expect(fp.defaultPreferences).to.have.property('network.proxy.autoconfig_url', '"http://url-to-proxy-auto-config"');
});
});
describe('#updatePreferences', function() {
// compat node 0.8 & 0.10
var encoding = process.version.indexOf('v0.8.') == 0 ? 'utf8': {encoding: 'utf8'};
var encoding = process.version.indexOf('v0.8.') === 0 ? 'utf8': {encoding: 'utf8'};
describe('should correctly output a string value in user.js', function() {

@@ -90,4 +140,124 @@ it('without new line characters', function() {

});
describe('#encoded', function() {
it('should work with a brand new profile', function(done) {
var fp = new FirefoxProfile();
fp.encoded(function(zippedProfile) {
expect(zippedProfile).to.be.equal(testProfiles.brandNewProfile.expectedZip);
done();
});
// encoded() results is not constant for more 'complex' profiles
// other encoded tests are done in test/spec/ tests
});
});
// 'id': null,
// 'name': null,
// 'unpack': true,
// 'version': null
describe('#__addonDetails', function() {
it('should correctly retrieve addon details from rdf that does not use namespace', function(done) {
var fp = new FirefoxProfile();
fp._addonDetails(path.join(__dirname, 'extensions/test.no-namespace-template.xpi'), function(extDetails) {
expect(extDetails).to.be.eql({
id: 'no-namespace@test.test',
name: 'test-extension without namespace',
unpack: true,
version: '2.1.0'
});
done();
});
});
});
it('should correctly retrieve addon details from rdf that uses namespace', function(done) {
var fp = new FirefoxProfile();
fp._addonDetails(path.join(__dirname, 'extensions/test.template.xpi'), function(extDetails) {
expect(extDetails).to.be.eql({
id: 'with-namespace@test.test',
name: 'test-extension with namespace',
unpack: false,
version: '2.2.99'
});
done();
});
});
});
describe('#_sanitizePref()', function() {
it('you correctly deal you boolean values', function() {
var fp = new FirefoxProfile();
expect(fp._sanitizePref('true')).to.be.true;
expect(fp._sanitizePref('false')).to.be.false;
});
});
describe('#addExtension', function() {
it('should unzip extensions in profile folder' , function(done) {
var fp = new FirefoxProfile();
fp.addExtension(path.join(__dirname, 'extensions/png-extension.xpi'), function() {
var exensionDir = path.join(fp.profileDir, 'extensions', 'id@test.test');
expect(fs.statSync(exensionDir).isDirectory()).to.be.true;
expect(fs.statSync(path.join(exensionDir, 'install.rdf')).isFile()).to.be.true;
expect(fs.statSync(path.join(exensionDir, 'breakpointConditionEditor.png')).isFile()).to.be.true;
done();
});
});
});
describe('#path', function() {
it('should return the profile directory', function() {
var fp = new FirefoxProfile();
expect(fp.path()).to.be.equal(fp.profileDir);
});
});
describe('#canAcceptUntrustedCerts', function() {
it('should return default value if not set', function() {
var fp = new FirefoxProfile();
expect(fp.canAcceptUntrustedCerts()).to.be.true;
});
});
describe('#setAcceptUntrustedCerts', function() {
it('should properly set value', function() {
var fp = new FirefoxProfile();
fp.setAcceptUntrustedCerts(false);
expect(fp.canAcceptUntrustedCerts()).to.be.false;
});
});
describe('#canAssumeUntrustedCertIssuer', function() {
it('should return default value if not set', function() {
var fp = new FirefoxProfile();
expect(fp.canAssumeUntrustedCertIssuer()).to.be.true;
});
});
describe('#setAssumeUntrustedCertIssuer', function() {
it('should properly set value', function() {
var fp = new FirefoxProfile();
fp.setAssumeUntrustedCertIssuer(0); // faulty
expect(fp.canAssumeUntrustedCertIssuer()).to.be.false;
});
});
describe('#nativeEventsEnabled', function() {
it('should return default value if not set', function() {
var fp = new FirefoxProfile();
expect(fp.nativeEventsEnabled()).to.be.true;
});
});
describe('#setNativeEventsEnabled', function() {
it('should properly set value', function() {
var fp = new FirefoxProfile();
fp.setNativeEventsEnabled(false); // faulty
expect(fp.nativeEventsEnabled()).to.be.false;
});
});
describe('#path', function() {
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc