Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gtoken

Package Overview
Dependencies
Maintainers
1
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gtoken - npm Package Compare versions

Comparing version 1.1.2 to 1.2.0

test/assets/key-no-email.json

29

lib/index.js

@@ -54,11 +54,21 @@ var gp12pem = require('google-p12-pem');

var mimeType = this._mime.lookup(this.keyFile);
if (mimeType === 'application/x-pkcs12') {
// detect .p12 file and convert to .pem on the fly
gp12pem(this.keyFile, handleKey);
} else if (mimeType === 'application/json') {
if (mimeType === 'application/json') {
// json file
fs.readFile(this.keyFile, handleJSONKey);
} else {
// assume .pem key otherwise
fs.readFile(this.keyFile, handleKey);
// Must be a .p12 file or .pem key
if (!self.iss) {
var error = new Error('email is required.');
error.code = 'MISSING_CREDENTIALS';
callback(error);
return;
}
if (mimeType === 'application/x-pkcs12') {
// convert to .pem on the fly
gp12pem(this.keyFile, handleKey);
} else {
// assume .pem key otherwise
fs.readFile(this.keyFile, handleKey);
}
}

@@ -84,2 +94,9 @@ } else {

if (!self.key || !self.iss) {
var error = new Error('private_key and client_email are required.');
error.code = 'MISSING_CREDENTIALS';
callback(error);
return;
}
self._requestToken(callback);

@@ -86,0 +103,0 @@ }

{
"name": "gtoken",
"version": "1.1.2",
"version": "1.2.0",
"description": "Node.js Google Authentication Service Account Tokens",

@@ -5,0 +5,0 @@ "main": "./lib/index.js",

@@ -8,2 +8,3 @@ var assert = require('assert');

var KEYFILEJSON = './test/assets/key.json';
var KEYFILENOEMAILJSON = './test/assets/key-no-email.json';
var KEYCONTENTS = fs.readFileSync(KEYFILE);

@@ -31,2 +32,7 @@ var KEYJSONCONTENTS = fs.readFileSync(KEYFILEJSON);

var TESTDATA_KEYFILENOEMAIL = {
scope: 'scope123', // or space-delimited string of scopes
keyFile: KEYFILE
};
var TESTDATA_KEYFILEJSON = {

@@ -37,2 +43,7 @@ scope: 'scope123', // or space-delimited string of scopes

var TESTDATA_KEYFILENOEMAILJSON = {
scope: 'scope123', // or space-delimited string of scopes
keyFile: KEYFILENOEMAILJSON
};
var TESTDATA_P12 = {

@@ -44,2 +55,7 @@ email: 'email@developer.gserviceaccount.com',

var TESTDATA_P12_NO_EMAIL = {
scope: 'scope123', // or space-delimited string of scopes
keyFile: P12FILE
};
var MIME = {

@@ -203,2 +219,10 @@ lookup: function(filename) {

it('should return error if iss is not set with .pem', function(done) {
var gtoken = GoogleToken(TESTDATA_KEYFILENOEMAIL);
gtoken.getToken(function(err) {
assert.strictEqual(err.code, 'MISSING_CREDENTIALS');
done();
});
});
it('should read .json key from file', function(done) {

@@ -224,2 +248,10 @@ var gtoken = GoogleToken(TESTDATA_KEYFILEJSON);

it('should return error if iss is not set with .json', function(done) {
var gtoken = GoogleToken(TESTDATA_KEYFILENOEMAILJSON);
gtoken.getToken(function(err) {
assert.strictEqual(err.code, 'MISSING_CREDENTIALS');
done();
});
});
it('should return cached token if not expired', function(done) {

@@ -266,2 +298,10 @@ var gtoken = GoogleToken(TESTDATA);

it('should return error if iss is not set with .p12', function(done) {
var gtoken = GoogleToken(TESTDATA_P12_NO_EMAIL);
gtoken.getToken(function(err) {
assert.strictEqual(err.code, 'MISSING_CREDENTIALS');
done();
});
});
describe('request', function() {

@@ -268,0 +308,0 @@ it('should be run with correct options', function(done) {

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