Merge pull request #31 from zeknox/test_suite - warvox - VoIP based wardialing tool, forked from rapid7/warvox.
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
---
(DIR) commit f4e3eb1b43a45ddf1c7999e48563234d8144f57a
(DIR) parent 60e7d18680788318e47abd21ada018d913f20eb7
(HTM) Author: HD Moore <hd_moore@rapid7.com>
Date: Sat, 24 Oct 2015 10:39:01 -0500
Merge pull request #31 from zeknox/test_suite
Added Initial Feature Tests for Login Page
Diffstat:
M app/controllers/application_contro… | 2 +-
M app/views/projects/index.html.erb | 72 ++++++++++++++-----------------
M spec/factories/jobs.rb | 2 +-
A spec/features/projects_spec.rb | 25 +++++++++++++++++++++++++
A spec/features/visitor/logins_spec.… | 58 ++++++++++++++++++++++++++++++
M spec/rails_helper.rb | 46 ++++++++++++++++----------------
A spec/support/auth_logic_helpers.rb | 21 +++++++++++++++++++++
7 files changed, 162 insertions(+), 64 deletions(-)
---
(DIR) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
@@ -23,7 +23,7 @@ private
def require_user
unless current_user
store_location
- flash[:notice] = "You must be logged in to access this page"
+ flash.now[:notice] = "You must be logged in to access this page"
redirect_to '/login'
return false
end
(DIR) diff --git a/app/views/projects/index.html.erb b/app/views/projects/index.html.erb
@@ -1,46 +1,40 @@
-<% if @projects.length > 0 %>
<h1 class='title'>WarVOX Projects</h1>
+<p>
+ <a class="btn" href="<%= new_project_path %>">
+ <i class="fa fa-plus"></i> Create Project
+ </a>
+</p>
<%= will_paginate @projects, :renderer => BootstrapPagination::Rails %>
-<table class='table table-striped ' width='90%'>
- <thead>
- <tr>
- <th>Name</th>
- <th>Description</th>
- <th>Jobs</th>
- <th>Calls</th>
- <th>Analyzed</th>
- <th>Created</th>
- <th>Actions</th>
- </tr>
- </thead>
- <tbody>
-
-<% @projects.each do |project| %>
- <tr>
- <td><%= link_to( h(project.name), project_path(project)) %></td>
- <td><%=truncate(project.description, :length => 40, :separator => '') %></td>
- <td><%= number_with_delimiter(project.jobs.count) %></td>
- <td><%= number_with_delimiter(project.calls.count) %></td>
- <td><%= number_with_delimiter(project.calls.where('analysis_completed_at IS NOT NULL').count) %></td>
- <td><%= time_ago_in_words(project.created_at) %> ago</td>
- <td>
- <a class="btn" href="<%= edit_project_path(project) %>"rel="tooltip" title="Update Project Information"><i class="fa fa-pencil"></i></a>
- <a class="btn" href="<%= project_path(project) %>" data-confirm="Delete this project?" data-method="delete" rel="nofollow tooltip" title="Delete Project"><i class="fa fa-trash"></i></a>
- </td>
- </tr>
-
-<% end %>
-</tbody>
+<table id='projects-table' class='table table-striped' width='90%'>
+ <thead>
+ <tr>
+ <th>Name</th>
+ <th>Description</th>
+ <th>Jobs</th>
+ <th>Calls</th>
+ <th>Analyzed</th>
+ <th>Created</th>
+ <th>Actions</th>
+ </tr>
+ </thead>
+ <tbody>
+ <% @projects.each do |project| %>
+ <tr>
+ <td><%= link_to( h(project.name), project_path(project)) %></td>
+ <td><%=truncate(project.description, :length => 40, :separator => '') %></td>
+ <td><%= number_with_delimiter(project.jobs.count) %></td>
+ <td><%= number_with_delimiter(project.calls.count) %></td>
+ <td><%= number_with_delimiter(project.calls.where('analysis_completed_at IS NOT NULL').count) %></td>
+ <td><%= time_ago_in_words(project.created_at) %> ago</td>
+ <td>
+ <a class="btn" href="<%= edit_project_path(project) %>"rel="tooltip" title="Update Project Information"><i class="fa fa-pencil"></i></a>
+ <a class="btn" href="<%= project_path(project) %>" data-confirm="Delete this project?" data-method="delete" rel="nofollow tooltip" title="Delete Project"><i class="fa fa-trash"></i></a>
+ </td>
+ </tr>
+ <% end %>
+ </tbody>
</table>
<%= will_paginate @projects, :renderer => BootstrapPagination::Rails %>
-<% else %>
-
-<h1 class='title'>No Projects</h1>
-<br/>
-
-<% end %>
-
-<a class="btn" href="<%= new_project_path %>"><i class="fa fa-plus"></i> Create Project </a>
(DIR) diff --git a/spec/factories/jobs.rb b/spec/factories/jobs.rb
@@ -27,7 +27,7 @@ FactoryGirl.define do
error nil
range { Faker::PhoneNumber.phone_number }
cid_mask { Faker::PhoneNumber.phone_number }
- seconds { Faker::Number.between(1, 300) }
+ seconds { Faker::Number.between(1, 299) }
lines { Faker::Number.between(1, 10000) }
end
(DIR) diff --git a/spec/features/projects_spec.rb b/spec/features/projects_spec.rb
@@ -0,0 +1,25 @@
+require 'rails_helper'
+
+RSpec.feature "Projects", type: :feature do
+
+ before(:each) do
+ @user = create(:user)
+ create_user_session(@user)
+ end
+
+ it "list all existing projects" do
+ project = create(:project)
+ visit projects_path
+ expect(page).to have_content "WarVOX Projects"
+ within "#projects-table" do
+ expect(page).to have_content "Name"
+ expect(page).to have_content "Description"
+ expect(page).to have_content "Jobs"
+ expect(page).to have_content "Calls"
+ expect(page).to have_content "Analyzed"
+ expect(page).to have_content "Created"
+ expect(page).to have_content "Actions"
+ expect(page).to have_content project.name
+ end
+ end
+end
(DIR) diff --git a/spec/features/visitor/logins_spec.rb b/spec/features/visitor/logins_spec.rb
@@ -0,0 +1,58 @@
+require 'rails_helper'
+
+RSpec.feature "Logins", type: :feature do
+ it "login with valid credentials" do
+ user = create(:user)
+ visit login_path
+ within "#new_user_session" do
+ expect(page).to have_content "Username"
+ expect(page).to have_content "Password"
+ fill_in "user_session_login", with: user.login
+ fill_in "user_session_password", with: 'RandomPass'
+ click_button "Sign in"
+ end
+ within "div.content" do
+ expect(page).to have_content "WarVOX Projects"
+ end
+ end
+
+ it "failed login with invalid password valid username" do
+ user = create(:user)
+ visit login_path
+ within "#new_user_session" do
+ fill_in "user_session_login", with: user.login
+ fill_in "user_session_password", with: 'WrongPassword'
+ click_button "Sign in"
+ end
+ expect(page).to have_content "Password is not valid"
+ end
+
+ it "failed login with invalid username valid password" do
+ user = create(:user)
+ visit login_path
+ within "#new_user_session" do
+ fill_in "user_session_login", with: user.login + "Wrong"
+ fill_in "user_session_password", with: 'RandomPass'
+ click_button "Sign in"
+ end
+ expect(page).to have_content "Login is not valid"
+ end
+
+ it "failed login with no input entered" do
+ visit login_path
+ within "#new_user_session" do
+ click_button "Sign in"
+ end
+ expect(page).to have_content "You did not provide any details for authentication."
+ end
+
+ it "failed login with no password entered" do
+ user = create(:user)
+ visit login_path
+ within "#new_user_session" do
+ fill_in "user_session_login", with: user.login
+ click_button "Sign in"
+ end
+ expect(page).to have_content "Password cannot be blank"
+ end
+end
(DIR) diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb
@@ -20,36 +20,36 @@ require 'rspec/rails'
# directory. Alternatively, in the individual `*_spec.rb` files, manually
# require only the support files necessary.
#
-# Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
+Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
# Checks for pending migrations before tests are run.
# If you are not using ActiveRecord, you can remove this line.
ActiveRecord::Migration.maintain_test_schema!
RSpec.configure do |config|
- # FactoryGirl Syntax
- config.include FactoryGirl::Syntax::Methods
+ # FactoryGirl Syntax
+ config.include FactoryGirl::Syntax::Methods
- # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
- config.fixture_path = "#{::Rails.root}/spec/fixtures"
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
- # If you're not using ActiveRecord, or you'd prefer not to run each of your
- # examples within a transaction, remove the following line or assign false
- # instead of true.
- config.use_transactional_fixtures = true
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
+ # examples within a transaction, remove the following line or assign false
+ # instead of true.
+ config.use_transactional_fixtures = true
- # RSpec Rails can automatically mix in different behaviours to your tests
- # based on their file location, for example enabling you to call `get` and
- # `post` in specs under `spec/controllers`.
- #
- # You can disable this behaviour by removing the line below, and instead
- # explicitly tag your specs with their type, e.g.:
- #
- # RSpec.describe UsersController, :type => :controller do
- # # ...
- # end
- #
- # The different available types are documented in the features, such as in
- # https://relishapp.com/rspec/rspec-rails/docs
- config.infer_spec_type_from_file_location!
+ # RSpec Rails can automatically mix in different behaviours to your tests
+ # based on their file location, for example enabling you to call `get` and
+ # `post` in specs under `spec/controllers`.
+ #
+ # You can disable this behaviour by removing the line below, and instead
+ # explicitly tag your specs with their type, e.g.:
+ #
+ # RSpec.describe UsersController, :type => :controller do
+ # # ...
+ # end
+ #
+ # The different available types are documented in the features, such as in
+ # https://relishapp.com/rspec/rspec-rails/docs
+ config.infer_spec_type_from_file_location!
end
(DIR) diff --git a/spec/support/auth_logic_helpers.rb b/spec/support/auth_logic_helpers.rb
@@ -0,0 +1,20 @@
+module Authlogic
+ module TestHelper
+ def create_user_session(user)
+ visit login_path
+ within "#new_user_session" do
+ expect(page).to have_content "Username"
+ expect(page).to have_content "Password"
+ fill_in "user_session_login", with: user.login
+ fill_in "user_session_password", with: user.password
+ click_button "Sign in"
+ end
+ end
+ end
+end
+
+# Make this available to just the request and feature specs
+RSpec.configure do |config|
+ config.include Authlogic::TestHelper, type: :request
+ config.include Authlogic::TestHelper, type: :feature
+end
+\ No newline at end of file