Module: AutoTest::Authentication

Included in:
AutoTest
Defined in:
lib/authentication.rb

Overview

This module deals with all functions concerning authentication of users in the application

Class Method Summary collapse

Class Method Details

.get_login_attributesObject

return the login attributes



37
38
39
# File 'lib/authentication.rb', line 37

def 
  @login_attributes
end

.get_login_buttonObject

get the login button



57
58
59
# File 'lib/authentication.rb', line 57

def 
  @login_button
end

.get_login_dataObject

get login data array



62
63
64
# File 'lib/authentication.rb', line 62

def 
  @data
end

.get_login_fieldsObject

get login fields



99
100
101
# File 'lib/authentication.rb', line 99

def 
  @fields
end

.get_login_namesObject

get login names



89
90
91
# File 'lib/authentication.rb', line 89

def 
  @names
end

.get_login_pathObject

get the login path



42
43
44
# File 'lib/authentication.rb', line 42

def 
  @login
end

.get_logout_pathObject

getter for logout path



25
26
27
# File 'lib/authentication.rb', line 25

def get_logout_path
  @logout
end

.get_unique_login_attribute_nameObject

get unique attribute name



109
110
111
# File 'lib/authentication.rb', line 109

def  
  @unique_login
end

.get_user_dataObject

get user data



147
148
149
# File 'lib/authentication.rb', line 147

def get_user_data
  @user_data
end

.get_usersObject

return the users



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/authentication.rb', line 124

def get_users
  if @db_users[0] then
    @users = @db_users[1].find(:all)
  else 
    index = .index()   
    @users = []     
    @db_users[1].find(:all).each do |u|
      .each do |d|
        if d[index] == u.send(.to_sym) then
          @users << u
        end
      end
    end
  end
  return @users
end

.get_users_from_db(user_class_name, bool) ⇒ Object

user function to determine if users are read from db



74
75
76
77
78
79
80
81
# File 'lib/authentication.rb', line 74

def get_users_from_db(user_class_name, bool)
  @users = user_class_name.find(:all)
  if bool then
    @db_users = [true, user_class_name]
  else 
    @db_users = [false, user_class_name]
  end
end

.init_login_dataObject

initialize login data array



15
16
17
# File 'lib/authentication.rb', line 15

def 
  @data = []
end

.init_usersObject

initialize the users array



9
10
11
12
# File 'lib/authentication.rb', line 9

def init_users
  @users = []
  @db_users = [false, nil]
end

.login(user, session) ⇒ Object

login a user



165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/authentication.rb', line 165

def (user, session)
  begin
    session.visit 
    user = user.class.find(user.id)
    hash = Hash.new
    hash["#{Test.get_sessions_array.index(session)}:#{session.current_path}"] = 
    Test.add_to_action_path hash
    Page.check_for_error_code(session)
    index = .index()        
    @db_users[1].find(:all).each do |u|
      .each do |d|
        if d[index] == u.send(.to_sym) then
          set_user_data([index])
        end
      end  
    end
    # fill in fields with user data, either from db or given by the tester
    if @db_users[0] then
      .each do |field|            
        session.fill_in field[1], :with => user.send(field[0].to_sym)
      end
    else
      .each_with_index do |field, i|
        session.fill_in field, :with => get_user_data[i]
      end
    end
    session.click_button 
    Page.check_for_error_code(session)
  # save from exception if user object has changed
  rescue (ActiveRecord::RecordNotFound)
    Test.sessions(Test.get_sessions_array.index(session), "depth", Test.get_max_depth+1)
    Test.sessions(Test.get_sessions_array.index(session), "current_depth", Test.get_sessions(Test.get_sessions_array.index(session), "depth"))
  end  
        
end

.logout(session) ⇒ Object

logout a user



152
153
154
155
156
157
158
159
160
161
162
# File 'lib/authentication.rb', line 152

def logout(session)
  begin
    hash = Hash.new
    hash["#{Test.get_sessions_array.index(session)}:#{session.current_path}"] = get_logout_path
    Test.add_to_action_path hash
    # logout the user by visiting the logout path
    session.visit get_logout_path
    Page.check_for_error_code(session)
  rescue => e
  end
end

.set_login_attribute_names(names, fields) ⇒ Object

user function to set the attribute_names and fields that are needed to login the argument are two arrays, the first are the database names of the attribute the second are the belonging field names



32
33
34
# File 'lib/authentication.rb', line 32

def (names, fields)
  @login_attributes = names.zip fields
end

.set_login_button(text) ⇒ Object

user function to set the text of the login button



52
53
54
# File 'lib/authentication.rb', line 52

def (text)
  @login_button = text
end

.set_login_data(*data) ⇒ Object

user function to set the login data



67
68
69
70
71
# File 'lib/authentication.rb', line 67

def (*data)
  data.each do |d|
    @data << d
  end
end

.set_login_fields(fields) ⇒ Object

user function to set login fields



94
95
96
# File 'lib/authentication.rb', line 94

def (fields)
  @fields = fields
end

.set_login_names(names) ⇒ Object

user function to set login names



84
85
86
# File 'lib/authentication.rb', line 84

def (names)
  @names = names
end

.set_login_path(path) ⇒ Object

user function to set the login path



47
48
49
# File 'lib/authentication.rb', line 47

def (path)
  @login = path
end

.set_logout_path(path) ⇒ Object

user function to set the logout path



20
21
22
# File 'lib/authentication.rb', line 20

def set_logout_path(path)
  @logout = path
end

.set_unique_login_attribute_name(name) ⇒ Object

user function to set unique attribute name



104
105
106
# File 'lib/authentication.rb', line 104

def (name)
  @unique_login = name
end

.set_user_data(value) ⇒ Object

set user data



142
143
144
# File 'lib/authentication.rb', line 142

def set_user_data(value)
  @user_data = value
end

.use_db_usersObject

get first element of db users, determine if users are read from db



114
115
116
# File 'lib/authentication.rb', line 114

def use_db_users
  @db_users[0]
end

.user_classObject

get second element of db users, the class of the user



119
120
121
# File 'lib/authentication.rb', line 119

def user_class
  @db_users[1]
end