-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from node-xmpp/events-fix
Events fix
- Loading branch information
Showing
4 changed files
with
45 additions
and
43 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
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
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
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 |
---|---|---|
|
@@ -89,11 +89,11 @@ function startServer(mechanism) { | |
return c2s | ||
} | ||
|
||
function registerHandler(cl) { | ||
function createClient(opts) { | ||
|
||
cl.on( | ||
'stanza', | ||
function(stanza) { | ||
var cl = new Client(opts) | ||
|
||
cl.on('stanza', function(stanza) { | ||
if (stanza.is('message') && | ||
// Important: never reply to errors! | ||
(stanza.attrs.type !== 'error')) { | ||
|
@@ -108,6 +108,8 @@ function registerHandler(cl) { | |
} | ||
} | ||
) | ||
|
||
return cl | ||
} | ||
|
||
describe('SASL', function() { | ||
|
@@ -120,19 +122,16 @@ describe('SASL', function() { | |
}) | ||
|
||
after(function(done) { | ||
c2s.shutdown() | ||
done() | ||
c2s.shutdown(done) | ||
}) | ||
|
||
it('should accept plain authentication', function(done) { | ||
var cl = new Client({ | ||
var cl = createClient({ | ||
jid: user.jid, | ||
password: user.password, | ||
preferred: Plain.id | ||
}) | ||
|
||
registerHandler(cl) | ||
|
||
cl.on('online', function() { | ||
done() | ||
}) | ||
|
@@ -144,13 +143,11 @@ describe('SASL', function() { | |
}) | ||
|
||
it('should not accept plain authentication', function(done) { | ||
var cl = new Client({ | ||
var cl = createClient({ | ||
jid: user.jid, | ||
password: 'secretsecret' | ||
}) | ||
|
||
registerHandler(cl) | ||
|
||
cl.on('online', function() { | ||
done('user is not valid') | ||
}) | ||
|
@@ -171,8 +168,7 @@ describe('SASL', function() { | |
}) | ||
|
||
after(function(done) { | ||
c2s.shutdown() | ||
done() | ||
c2s.shutdown(done) | ||
}) | ||
|
||
/* | ||
|
@@ -181,15 +177,13 @@ describe('SASL', function() { | |
*/ | ||
it('should accept google authentication', function(done) { | ||
/*jshint camelcase: false */ | ||
var gtalk = new Client({ | ||
var gtalk = createClient({ | ||
jid: '[email protected]', | ||
oauth2_token: 'xxxx.xxxxxxxxxxx', // from OAuth2 | ||
oauth2_auth: 'http://www.google.com/talk/protocol/auth', | ||
host: 'localhost' | ||
}) | ||
|
||
registerHandler(gtalk) | ||
|
||
gtalk.on('online', function() { | ||
done() | ||
}) | ||
|
@@ -210,20 +204,17 @@ describe('SASL', function() { | |
}) | ||
|
||
after(function(done) { | ||
c2s.shutdown() | ||
done() | ||
c2s.shutdown(done) | ||
}) | ||
|
||
|
||
it('should accept digest md5 authentication', function(done) { | ||
var cl = new Client({ | ||
var cl = createClient({ | ||
jid: user.jid, | ||
password: user.password, | ||
preferred: 'DIGEST-MD5' | ||
}) | ||
|
||
registerHandler(cl) | ||
|
||
cl.on('online', function() { | ||
done() | ||
}) | ||
|
@@ -292,18 +283,15 @@ describe('SASL', function() { | |
}) | ||
|
||
after(function(done) { | ||
c2s.shutdown() | ||
done() | ||
c2s.shutdown(done) | ||
}) | ||
|
||
it('should accept anonymous authentication', function(done) { | ||
var cl = new Client({ | ||
var cl = createClient({ | ||
jid: '@localhost', | ||
preferred: Anonymous.id | ||
}) | ||
|
||
registerHandler(cl) | ||
|
||
cl.on('online', function(online) { | ||
online.jid.local.length.should.equal(32) | ||
online.jid.resource.length.should.equal(16) | ||
|