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

aerogear-sender-client

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aerogear-sender-client - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

21

lib/aerogear-sender-client.js

@@ -27,5 +27,4 @@ /* AeroGear JavaScript Library

// Otherwise the 'http' module is stashed
var caller = (serverSettings.protocol === "https:") ? https : http;
var that = this,
var caller = (serverSettings.protocol === "https:") ? https : http,
that = this,
req = caller.request( serverSettings, function( res ) {

@@ -35,2 +34,17 @@

that.emit( "error", res.statusCode );
} else if( res.statusCode === 301 || res.statusCode === 302 || res.statusCode === 303 ) {
//Moved Status, Need to resend
if( !res.headers.location ) {
that.emit( "error", "redirect url is not available" );
} else {
var url = urlParser.parse( res.headers.location );
//Better way i think
serverSettings.protocol = url.protocol;
serverSettings.hostname = url.hostname;
serverSettings.port = url.port;
serverSettings.path = url.pathname;
send.call( that, serverSettings, message );
}
} else {

@@ -68,3 +82,2 @@ res.setEncoding('utf8');

var AeroGear = {};

@@ -71,0 +84,0 @@

2

package.json
{
"name": "aerogear-sender-client",
"version": "0.0.2",
"version": "0.0.3",
"description": "Sender api for the AeroGear Unified Push server",

@@ -5,0 +5,0 @@ "homepage": "https://github.com/aerogear/aerogear-unifiedpush-nodejs-client",

@@ -134,1 +134,151 @@ var chai = require( "chai" ),

});
describe( "Sender - Handle Moved Status Codes", function() {
var sender = AeroGear.Sender( "http://localhost:8080/ag-push" ),
applicationID = "12345",
masterSecret = "54321",
settings = {},
message = {};
beforeEach( function() {
settings = {};
message = {};
});
describe( "Endpoint returns moved", function() {
it( "broadcast should be called with success", function( done ) {
nock( "http://localhost:8080" )
.matchHeader('Accept', 'application/json')
.matchHeader('Content-type', 'application/json')
.post( "/ag-push/rest/sender/broadcast" )
.reply( 302,{},{'location': "http://localhost:8080/rest/new/sender"} )
.post( "/rest/new/sender" )
.reply( 200, {} );
settings.applicationID = applicationID;
settings.masterSecret = masterSecret;
sender.broadcast( message, settings ).on( "success", function( response ) {
expect( response ).to.be.ok;
done();
});
});
});
describe( "Endpoint returns moved, with no new location", function() {
it( "broadcast should be called with error", function( done ) {
nock( "http://localhost:8080" )
.matchHeader('Accept', 'application/json')
.matchHeader('Content-type', 'application/json')
.post( "/ag-push/rest/sender/broadcast" )
.reply( 302,{},{} );
settings.applicationID = applicationID;
settings.masterSecret = masterSecret;
sender.broadcast( message, settings ).on( "error", function( error ) {
expect( error ).to.be.ok;
expect( error ).to.equal( "redirect url is not available" );
done();
});
});
});
// describe( "Endpoint returns moved", function() {
// it( "sendTo should be called with success", function( done ) {
// nock( "http://localhost:8080" )
// .matchHeader('Accept', 'application/json')
// .matchHeader('Content-type', 'application/json')
// .post( "/ag-push/rest/sender/selected" )
// .reply( 302,{},{'location': "http://localhost:8080/rest/new/sender"} )
// .post( "/rest/new/sender" )
// .reply( 200, {} );
// settings.applicationID = applicationID;
// settings.masterSecret = masterSecret;
// sender.sendTo( message, settings ).on( "success", function( response ) {
// expect( response ).to.be.ok;
// done();
// });
// });
// });
// describe( "Endpoint returns moved, with no new location", function() {
// it( "sendTo should be called with error", function( done ) {
// nock( "http://localhost:8080" )
// .matchHeader('Accept', 'application/json')
// .matchHeader('Content-type', 'application/json')
// .post( "/ag-push/rest/sender/selected" )
// .reply( 302,{},{} );
// settings.applicationID = applicationID;
// settings.masterSecret = masterSecret;
// sender.sendTo( message, settings ).on( "error", function( error ) {
// expect( error ).to.be.ok;
// expect( error ).to.equal( "redirect url is not available" );
// done();
// });
// });
// });
});
describe( "Sender - Handle Moved Status Codes", function() {
var sender = AeroGear.Sender( "http://localhost:8080/ag-push" ),
applicationID = "12345",
masterSecret = "54321",
settings = {},
message = {};
beforeEach( function() {
settings = {};
message = {};
});
describe( "Endpoint returns moved", function() {
it( "sendTo should be called with success", function( done ) {
nock( "http://localhost:8080" )
.matchHeader('Accept', 'application/json')
.matchHeader('Content-type', 'application/json')
.post( "/ag-push/rest/sender/selected" )
.reply( 302,{},{'location': "http://localhost:8080/rest/new/sender"} )
.post( "/rest/new/sender" )
.reply( 200, {} );
settings.applicationID = applicationID;
settings.masterSecret = masterSecret;
sender.sendTo( message, settings ).on( "success", function( response ) {
expect( response ).to.be.ok;
done();
});
});
});
describe( "Endpoint returns moved, with no new location", function() {
it( "sendTo should be called with error", function( done ) {
nock( "http://localhost:8080" )
.matchHeader('Accept', 'application/json')
.matchHeader('Content-type', 'application/json')
.post( "/ag-push/rest/sender/selected" )
.reply( 302,{},{} );
settings.applicationID = applicationID;
settings.masterSecret = masterSecret;
sender.sendTo( message, settings ).on( "error", function( error ) {
expect( error ).to.be.ok;
expect( error ).to.equal( "redirect url is not available" );
done();
});
});
});
});

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