From 3c7ea9195c9c2cbddd8227cf7d268e19260e7ccb Mon Sep 17 00:00:00 2001 From: shabbir Date: Thu, 22 Feb 2018 11:09:07 -0500 Subject: [PATCH 1/2] solution --- Gemfile.lock | 117 ++++++++++++++-------- app.rb | 12 ++- features/.DS_Store | Bin 0 -> 6148 bytes features/login.feature | 5 +- features/logout.feature | 9 +- features/step_definitions/login_steps.rb | 15 ++- features/step_definitions/logout_steps.rb | 16 ++- 7 files changed, 120 insertions(+), 54 deletions(-) create mode 100644 features/.DS_Store diff --git a/Gemfile.lock b/Gemfile.lock index da8b141..dd53fb1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,61 +1,95 @@ GEM remote: https://rubygems.org/ specs: - builder (3.2.2) - capybara (2.4.4) - mime-types (>= 1.16) + addressable (2.5.2) + public_suffix (>= 2.0.2, < 4.0) + backports (3.11.1) + builder (3.2.3) + capybara (2.18.0) + addressable + mini_mime (>= 0.1.3) nokogiri (>= 1.3.3) rack (>= 1.0.0) rack-test (>= 0.5.4) - xpath (~> 2.0) - coderay (1.1.0) - cucumber (1.3.17) + xpath (>= 2.0, < 4.0) + coderay (1.1.2) + cucumber (3.1.0) builder (>= 2.1.2) - diff-lcs (>= 1.1.3) - gherkin (~> 2.12) + cucumber-core (~> 3.1.0) + cucumber-expressions (~> 5.0.4) + cucumber-wire (~> 0.0.1) + diff-lcs (~> 1.3) + gherkin (~> 5.0) multi_json (>= 1.7.5, < 2.0) - multi_test (>= 0.1.1) + multi_test (>= 0.1.2) + cucumber-core (3.1.0) + backports (>= 3.8.0) + cucumber-tag_expressions (~> 1.1.0) + gherkin (>= 5.0.0) + cucumber-expressions (5.0.13) cucumber-sinatra (0.5.0) templater (>= 1.0.0) - diff-lcs (1.2.5) + cucumber-tag_expressions (1.1.1) + cucumber-wire (0.0.1) + diff-lcs (1.3) extlib (0.9.16) - gherkin (2.12.2) - multi_json (~> 1.3) - haml (4.0.6) + ffi (1.9.21) + gherkin (5.0.0) + haml (5.0.4) + temple (>= 0.8.0) tilt - highline (1.6.21) - method_source (0.8.2) - mime-types (2.4.3) - mini_portile (0.6.1) - multi_json (1.10.1) - multi_test (0.1.1) - nokogiri (1.6.4.1) - mini_portile (~> 0.6.0) - pry (0.10.1) + highline (1.7.10) + method_source (0.9.0) + mini_mime (1.0.0) + mini_portile2 (2.3.0) + multi_json (1.13.1) + multi_test (0.1.2) + mustermann (1.0.2) + nokogiri (1.8.2) + mini_portile2 (~> 2.3.0) + pry (0.11.3) coderay (~> 1.1.0) - method_source (~> 0.8.1) - slop (~> 3.4) - rack (1.5.2) - rack-protection (1.5.3) + method_source (~> 0.9.0) + public_suffix (3.0.2) + rack (2.0.4) + rack-protection (2.0.1) rack - rack-test (0.6.2) - rack (>= 1.0) - rspec-expectations (3.1.2) + rack-test (0.8.2) + rack (>= 1.0, < 3) + rb-fsevent (0.10.2) + rb-inotify (0.9.10) + ffi (>= 0.5.0, < 2) + rspec (3.7.0) + rspec-core (~> 3.7.0) + rspec-expectations (~> 3.7.0) + rspec-mocks (~> 3.7.0) + rspec-core (3.7.1) + rspec-support (~> 3.7.0) + rspec-expectations (3.7.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.1.0) - rspec-support (3.1.2) - sinatra (1.4.5) - rack (~> 1.4) - rack-protection (~> 1.4) - tilt (~> 1.3, >= 1.3.4) - slop (3.6.0) + rspec-support (~> 3.7.0) + rspec-mocks (3.7.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.7.0) + rspec-support (3.7.1) + sass (3.5.5) + sass-listen (~> 4.0.0) + sass-listen (4.0.0) + rb-fsevent (~> 0.9, >= 0.9.4) + rb-inotify (~> 0.9, >= 0.9.7) + sinatra (2.0.1) + mustermann (~> 1.0) + rack (~> 2.0) + rack-protection (= 2.0.1) + tilt (~> 2.0) templater (1.0.0) diff-lcs (>= 1.1.2) extlib (>= 0.9.5) highline (>= 1.4.0) - tilt (1.4.1) - xpath (2.0.0) - nokogiri (~> 1.3) + temple (0.8.0) + tilt (2.0.8) + xpath (3.0.0) + nokogiri (~> 1.8) PLATFORMS ruby @@ -66,5 +100,10 @@ DEPENDENCIES cucumber-sinatra haml pry + rspec rspec-expectations + sass sinatra + +BUNDLED WITH + 1.16.1 diff --git a/app.rb b/app.rb index 670284d..bb79cb0 100644 --- a/app.rb +++ b/app.rb @@ -31,7 +31,15 @@ def logged_in? end get "/dashboard" do - @username = session[:user] - haml :dashboard + #@username = session[:user] + #haml :dashboard + #first check if user is authenticated or not + if logged_in? + @username = session[:user] + haml :dashboard + else + @message = 'Unauthorized access!' + end + end end diff --git a/features/.DS_Store b/features/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..b2a02abbb828e5f97ad9b8a4cead1577aadf05b2 GIT binary patch literal 6148 zcmeHK-EPw`6h7VxOF@HNOxiAUgTzIJT2NsKAw}J|*d0<4Tmb44l5LSfT;+#qluo(X zLyR}zQFsC#2fkw)XwxCI8-z9=>G(Ub&u7P9Yda<)F{q**kxN7loUwHS#W}|9>`S&{ zYPeCTJ~FyT2NY94ZOPE2DOQ3O0t<0q&~@HQD0i(`w;i}J%sF*fi1H5{i& zQFgoE#L8;x+VwT3-FDjR&fDRUoD9pLtcpR9zgAC46o)2$A!Yh24#Jm7JQ=wgJ2ESS zB#ZO8^f#}PERvIftg@(3{X7rKBXHF~BX?^$ebDcByx!yPtm93$??3E#{YU-T%yBmF z^q%hRzd!ys{WLo{V^y)6VmnoK+u%?5jNq@reHi9hDzii6azASjx`NDO$eL5xko6Q9 z^FL`L`?8AIm}WyVXmSP2{K=e~S75GoidF%uz{M2c{lSAX`UY!_YU@Cut^mLms+A$; z4+Z9U27QCIMzp|$rUErpm@9_Rbkut$&o@|W)N~T&@*&K~!rV}V8Xf(6DxHL{(Uw*L ztH7cHtNPL9^Z(hO@BfP=`(zcc3S24$L~D1rJHV98*}612K5ISrKAes7YK@A5!W_pc f;G=j8t_*D+2SDFotr0aa`yrrYu!U9NpDOSJeHq#G literal 0 HcmV?d00001 diff --git a/features/login.feature b/features/login.feature index 3fff7cf..d08cf68 100644 --- a/features/login.feature +++ b/features/login.feature @@ -5,6 +5,5 @@ Feature: Login Page Scenario: Authenticated User Given the login page - When I log in with proper credentials - Then I should see the secret page - + When I log in with username and password as "admin" + Then I should see the secret page with my my username "admin" diff --git a/features/logout.feature b/features/logout.feature index 251c445..e3bc2aa 100644 --- a/features/logout.feature +++ b/features/logout.feature @@ -1 +1,8 @@ -#Add your codez here +Feature: Logout functionality + When I want to end my session + I should be able to logout + +Scenario: User logs out + Given user secret page with credentials "admin" + When I click on "Logout" + Then I should be redirected to logout page with a message "You have been logged out" diff --git a/features/step_definitions/login_steps.rb b/features/step_definitions/login_steps.rb index 61f803a..17d6906 100644 --- a/features/step_definitions/login_steps.rb +++ b/features/step_definitions/login_steps.rb @@ -1,14 +1,13 @@ Given(/^the login page$/) do - #put your code here - pending + visit('http://localhost:4567') end -When(/^I log in with proper credentials$/) do - #put your code here - pending +When(/^I log in with username and password as "(.*?)"$/) do |credential| + fill_in 'username', :with => credential + fill_in 'password', :with => credential + click_button 'Login' end -Then(/^I should see the secret page$/) do - #put your code here - pending +Then(/^I should see the secret page with my my username "(.*?)"$/) do |username| + expect(page).to have_content username end diff --git a/features/step_definitions/logout_steps.rb b/features/step_definitions/logout_steps.rb index 251c445..5a4ed03 100644 --- a/features/step_definitions/logout_steps.rb +++ b/features/step_definitions/logout_steps.rb @@ -1 +1,15 @@ -#Add your codez here +Given (/^user secret page with credentials "(.*?)"$/) do |credentails| + steps %{ + Given the login page + When I log in with username and password as "#{credentails}" + Then I should see the secret page with my my username "#{credentails}" + } +end + +When (/^I click on "(.*?)"$/) do |link| + click_link link +end + +Then(/^I should be redirected to logout page with a message "(.*?)"$/) do |message| + expect(page).to have_content message +end From 7652a4d68cb6a6fb7fd946a091bb4d53c8f6ed67 Mon Sep 17 00:00:00 2001 From: shabbir Date: Thu, 22 Feb 2018 15:13:10 -0500 Subject: [PATCH 2/2] complete solution --- app.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app.rb b/app.rb index bb79cb0..fb3cbc7 100644 --- a/app.rb +++ b/app.rb @@ -39,6 +39,8 @@ def logged_in? haml :dashboard else @message = 'Unauthorized access!' + #redirect to home page + haml :index end end