summaryrefslogtreecommitdiff
path: root/users/test/functional
diff options
context:
space:
mode:
authorAzul <azul@riseup.net>2012-09-27 22:39:08 +0200
committerAzul <azul@riseup.net>2012-09-27 22:39:08 +0200
commitebbfe3d77efddbe8f97fa82c171632ac4cfcf6da (patch)
treeb81b55476f4f7889af0e346ebf5dc95afc4a02af /users/test/functional
parent1208257bcc0e2a6648b68433a7b7e24791f92583 (diff)
added in leap web users - one repo to rule them all
Diffstat (limited to 'users/test/functional')
-rw-r--r--users/test/functional/.gitkeep0
-rw-r--r--users/test/functional/sessions_controller_test.rb73
-rw-r--r--users/test/functional/users_controller_test.rb33
3 files changed, 106 insertions, 0 deletions
diff --git a/users/test/functional/.gitkeep b/users/test/functional/.gitkeep
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/users/test/functional/.gitkeep
diff --git a/users/test/functional/sessions_controller_test.rb b/users/test/functional/sessions_controller_test.rb
new file mode 100644
index 0000000..7876d84
--- /dev/null
+++ b/users/test/functional/sessions_controller_test.rb
@@ -0,0 +1,73 @@
+require 'test_helper'
+
+class SessionsControllerTest < ActionController::TestCase
+
+ def setup
+ @client_hex = 'a123'
+ @client_rnd = @client_hex.hex
+ @server_hex = 'b123'
+ @server_rnd = @server_hex.hex
+ @server_rnd_exp = 'e123'.hex
+ @server_handshake = stub :aa => @client_rnd, :bb => @server_rnd, :b => @server_rnd_exp
+ end
+
+ test "should get login screen" do
+ get :new
+ assert_response :success
+ end
+
+ test "should perform handshake" do
+ user = stub :login => "me", :id => 123
+ user.expects(:initialize_auth).
+ with(@client_rnd).
+ returns(@server_handshake)
+ User.expects(:find_by_param).with(user.login).returns(user)
+ post :create, :login => user.login, 'A' => @client_hex
+ assert_equal @server_handshake, session[:handshake]
+ assert_response :success
+ assert_json_response :B => @server_hex
+ end
+
+ test "should report user not found" do
+ unknown = "login_that_does_not_exist"
+ User.expects(:find_by_param).with(unknown).raises(RECORD_NOT_FOUND)
+ post :create, :login => unknown
+ assert_response :success
+ assert_json_response :errors => {"login" => ["unknown user"]}
+ end
+
+ test "should authorize" do
+ session[:handshake] = @server_handshake
+ user = stub :login => "me", :id => 123
+ user.expects(:authenticate!).
+ with(@client_rnd, @server_handshake).
+ returns(@server_auth)
+ User.expects(:find_by_param).with(user.login).returns(user)
+ post :update, :id => user.login, :client_auth => @client_hex
+ assert_nil session[:handshake]
+ assert_json_response :M2 => @server_auth
+ assert_equal user.id, session[:user_id]
+ end
+
+ test "should report wrong password" do
+ session[:handshake] = @server_handshake
+ user = stub :login => "me", :id => 123
+ user.expects(:authenticate!).
+ with(@client_rnd, @server_handshake).
+ raises(WRONG_PASSWORD)
+ User.expects(:find_by_param).with(user.login).returns(user)
+ post :update, :id => user.login, :client_auth => @client_hex
+ assert_nil session[:handshake]
+ assert_nil session[:user_id]
+ assert_json_response :errors => {"password" => ["wrong password"]}
+ end
+
+ test "logout should reset sessions user_id" do
+ session[:user_id] = "set"
+ delete :destroy
+ assert_nil session[:user_id]
+ assert_response :redirect
+ assert_redirected_to root_url
+ end
+
+end
diff --git a/users/test/functional/users_controller_test.rb b/users/test/functional/users_controller_test.rb
new file mode 100644
index 0000000..1cb28a6
--- /dev/null
+++ b/users/test/functional/users_controller_test.rb
@@ -0,0 +1,33 @@
+require 'test_helper'
+
+class UsersControllerTest < ActionController::TestCase
+ test "should get new" do
+ get :new
+ assert_equal User, assigns(:user).class
+ assert_response :success
+ end
+
+ test "should create new user" do
+ params = User.valid_attributes_hash
+ user = stub params.merge(:id => 123)
+ params.stringify_keys!
+ User.expects(:create!).with(params).returns(user)
+ post :create, :user => params
+ assert_nil session[:user_id]
+ assert_response :redirect
+ assert_redirected_to root_url
+ end
+
+ test "should redirect to signup form on failed attempt" do
+ params = User.valid_attributes_hash.slice(:login)
+ user = User.new(params)
+ params.stringify_keys!
+ User.expects(:create!).with(params).raises(VALIDATION_FAILED.new(user))
+ post :create, :user => params
+ assert_nil session[:user_id]
+ assert_equal user, assigns[:user]
+ assert_response :redirect
+ assert_redirected_to new_user_path
+ end
+
+end