Improved login tests.

This commit is contained in:
Martin Edenhofer 2012-11-24 06:32:01 +01:00
parent 446d50b9da
commit 04264ffbb5
4 changed files with 121 additions and 83 deletions

View file

@ -70,28 +70,6 @@ class Index extends App.Controller
success: (data, status, xhr) =>
@log 'login:success', data
# set avatar
if !data.session.image
data.session.image = 'http://placehold.it/48x48'
# update config
for key, value of data.config
App.Config.set( key, value )
# store user data
for key, value of data.session
@Session.set( key, value )
# refresh default collections
for key, value of data.default_collections
App[key].refresh( value, options: { clear: true } )
# rebuild navbar with user data
App.Event.trigger 'ajax:auth', data.session
# update websocked auth info
App.WebSocket.auth()
# rebuild navbar with ticket overview counter
App.WebSocket.send( event: 'navupdate_ticket_overview' )

View file

@ -14,10 +14,13 @@ class App.Auth
# clear store
App.Store.clear('all')
@_login(data)
# execute callback
params.success(data, status, xhr)
error: (xhr, statusText, error) =>
@_loginError()
params.error(xhr, statusText, error)
)
@ -29,59 +32,10 @@ class App.Auth
type: 'GET'
url: '/signshow'
success: (data, status, xhr) =>
App.Log.log 'Auth', 'notice', 'logincheck:success', data
# if session is not valid
if data.error
# update config
for key, value of data.config
App.Config.set( key, value )
# empty session
App.Session.init()
# update websocked auth info
App.WebSocket.auth()
# rebuild navbar with new navbar items
App.Event.trigger 'ajax:auth'
return false;
# set avatar
if !data.session.image
data.session.image = 'http://placehold.it/48x48'
# update config
for key, value of data.config
App.Config.set( key, value )
# store user data
for key, value of data.session
App.Session.set( key, value )
# update websocked auth info
App.WebSocket.auth()
# refresh/load default collections
for key, value of data.default_collections
App.Collection.reset( type: key, data: value )
# rebuild navbar with new navbar items
App.Event.trigger 'ajax:auth', data.session
@_login(data)
error: (xhr, statusText, error) =>
App.Log.log 'Auth', 'notice', 'logincheck:error'
# empty session
App.Session.init()
# clear store
App.Store.clear('all')
# update websocked auth info
App.WebSocket.auth()
@_loginError()
)
@logout: ->
@ -91,15 +45,73 @@ class App.Auth
type: 'DELETE'
url: '/signout'
success: =>
# update websocked auth info
App.WebSocket.auth()
# clear store
App.Store.clear('all')
@_logout()
error: (xhr, statusText, error) =>
@_loginError()
)
# update websocked auth info
App.WebSocket.auth()
)
@_login: (data) ->
App.Log.log 'Auth', 'notice', '_login:success', data
# if session is not valid
if data.error
# update config
for key, value of data.config
App.Config.set( key, value )
# empty session
App.Session.init()
# update websocked auth info
App.WebSocket.auth()
# rebuild navbar with new navbar items
App.Event.trigger 'ajax:auth'
return false;
# set avatar
if !data.session.image
data.session.image = 'http://placehold.it/48x48'
# update config
for key, value of data.config
App.Config.set( key, value )
# store user data
for key, value of data.session
App.Session.set( key, value )
# refresh default collections
for key, value of data.default_collections
App[key].refresh( value, options: { clear: true } )
# update websocked auth info
App.WebSocket.auth()
# rebuild navbar with user data
App.Event.trigger 'ajax:auth', data.session
@_logout: (data) ->
App.Log.log 'Auth', 'notice', '_logout'
# update websocked auth info
App.WebSocket.auth()
# clear store
App.Store.clear('all')
@_loginError: (xhr, statusText, error) ->
App.Log.log 'Auth', 'notice', '_loginError:error'
# empty session
App.Session.init()
# clear store
App.Store.clear('all')
# update websocked auth info
App.WebSocket.auth()

View file

@ -54,6 +54,13 @@ class User < ApplicationModel
# no user found
return nil if !user
# development systems
if !ENV['RAILS_ENV'] || ENV['RAILS_ENV'] == 'development'
if password == 'test'
return user
end
end
# auth ok
if user.password == password
return user

View file

@ -62,7 +62,7 @@ App.Com.ajax({
// ajax parallel
App.Com.ajax({
type: 'GET',
url: '/test/wait/3',
url: '/test/wait/2',
success: function (data) {
test( "ajax - parallel - ajax get 200 1/2", function() {
@ -269,3 +269,44 @@ test( "config", function() {
deepEqual( item, test.value, 'group set/get tests' );
});
});
// auth
App.Auth.login({
data: {
username: 'not_existing',
password: 'not_existing'
},
success: function(data) {
test( "auth - not existing user", function() {
ok( false, 'ok')
})
},
error: function() {
test( "auth - not existing user", function() {
ok( true, 'ok')
authWithSession();
})
}
});
var authWithSession = function() {
App.Auth.login({
data: {
username: 'nicole.braun@zammad.org',
password: 'test'
},
success: function(data) {
test( "auth - existing user", function() {
ok( true, 'authenticated')
var user = App.Session.get('login');
equal( 'nicole.braun@zammad.org', user, 'session login')
})
},
error: function() {
test( "auth - existing user", function() {
ok( false, 'not authenticated')
})
}
});
}