Browse Source
Fix NICK command behaviour to RFC
according to the RFC the correct response to the NICK command then it's
changing a nickname is to send a NICK command to the user from the
original nickname.
This patch changes the behaviour and removes a duplicate declearation of
the function.
fix/nickname
Sheogorath
5 years ago
No known key found for this signature in database
GPG Key ID: 1F05CC3635CDDFFD
2 changed files with
23 additions and
7 deletions
src/user.js
test/user.js
@ -1,12 +1,15 @@
function User ( socket , authenticatedDefault ) {
this . registered = false
this . authenticated = authenticatedDefault
this . nickname = ""
this . nickname = undefined
this . connection = socket
this . realname = ""
this . username = ""
this . setNickname = function ( nickname ) {
if ( this . nickname !== undefined ) {
this . sendRaw ( ` : ${ this . nickname } NICK ${ nickname } ` )
}
this . nickname = nickname
}
@ -26,12 +29,6 @@ function User(socket, authenticatedDefault) {
this . getAddress = function ( ) {
return this . connection . address ( ) . address
}
this . setNickname = function ( nickname ) {
this . nickname = nickname
}
this . setRealName = function ( realname ) {
this . realname = realname
}
this . closeConnection = function ( ) {
this . connection . destroy ( )
@ -62,4 +62,23 @@ describe('User', function () {
user . closeConnection ( )
} )
} )
describe ( '#setNickname(nickname)' , function ( ) {
it ( 'should not answer on inital setting of nickname' , function ( ) {
let mockedSock = { }
const user = new User ( mockedSock , true )
user . setNickname ( "some_nick" )
assert . equal ( user . getNickname ( ) , "some_nick" )
} )
it ( 'should answer with NICK message from original nick on rename' , function ( done ) {
let mockedSock = { write : function ( data ) {
assert . equal ( data , ":some_nick NICK changed_nick\r\n" )
done ( )
} }
const user = new User ( mockedSock , true )
user . setNickname ( "some_nick" )
user . setNickname ( "changed_nick" )
} )
} )
} )