From 661e02261671519f8d7bb8682380f81d956575d9 Mon Sep 17 00:00:00 2001 From: Katherine Martin Date: Tue, 5 Dec 2023 16:37:20 +0000 Subject: [PATCH 1/5] Update users yml to have correct password for registered and completed users --- db/seeds/users.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/seeds/users.yml b/db/seeds/users.yml index 7a8caa39e..6583098fa 100644 --- a/db/seeds/users.yml +++ b/db/seeds/users.yml @@ -1,6 +1,6 @@ --- registered@example.com: - password: <%= ENV.fetch('USER_PASSWORD', 'Str0ngPa$$word') %> + password: <%= ENV.fetch('USER_PASSWORD', 'Str0ngPa$$word12') %> terms_and_conditions_agreed_at: <%= 1.minute.ago %> confirmed@example.com: @@ -9,7 +9,7 @@ confirmed@example.com: confirmed_at: <%= 1.minute.ago %> completed@example.com: - password: <%= ENV.fetch('USER_PASSWORD', 'Str0ngPa$$w0rd') %> + password: <%= ENV.fetch('USER_PASSWORD', 'Str0ngPa$$w0rd12') %> terms_and_conditions_agreed_at: <%= 1.minute.ago %> confirmed_at: <%= 1.minute.ago %> first_name: Demo From 192317dfb508cb8ac3e5ceb78352e721f79141b2 Mon Sep 17 00:00:00 2001 From: Katherine Martin <78093815+martikat@users.noreply.github.com> Date: Thu, 7 Dec 2023 16:19:24 +0000 Subject: [PATCH 2/5] Centralise user_password so it can be used in multiple files --- config/application.rb | 2 ++ db/seeds/users.yml | 6 +++--- lib/tasks/eyfs.rake | 2 +- spec/config_spec.rb | 9 +++++++++ ui/pages/sign_in.rb | 2 +- 5 files changed, 16 insertions(+), 5 deletions(-) diff --git a/config/application.rb b/config/application.rb index 9749a9806..2fe90adbc 100644 --- a/config/application.rb +++ b/config/application.rb @@ -59,6 +59,8 @@ class Application < Rails::Application config.user_timeout_warning_minutes = ENV.fetch('TIMEOUT_WARNING_MINUTES', '20').to_i config.user_timeout_modal_visible = ENV.fetch('TIMEOUT_MODAL_VISIBLE', '5').to_i + config.user_password = ENV.fetch('USER_PASSWORD', 'Str0ngPa$$word12') + # Contentful config.contentful_space = ENV.fetch('CONTENTFUL_SPACE', credentials.dig(:contentful, :space)) config.contentful_delivery_access_token = ENV.fetch('CONTENTFUL_DELIVERY_TOKEN', credentials.dig(:contentful, :delivery_access_token)) diff --git a/db/seeds/users.yml b/db/seeds/users.yml index 6583098fa..c4bf2d284 100644 --- a/db/seeds/users.yml +++ b/db/seeds/users.yml @@ -1,15 +1,15 @@ --- registered@example.com: - password: <%= ENV.fetch('USER_PASSWORD', 'Str0ngPa$$word12') %> + password: <%= Rails.configuration.user_password %> terms_and_conditions_agreed_at: <%= 1.minute.ago %> confirmed@example.com: - password: <%= ENV.fetch('USER_PASSWORD', 'Str0ngPa$$w0rd12') %> + password: <%= Rails.configuration.user_password %> terms_and_conditions_agreed_at: <%= 1.minute.ago %> confirmed_at: <%= 1.minute.ago %> completed@example.com: - password: <%= ENV.fetch('USER_PASSWORD', 'Str0ngPa$$w0rd12') %> + password: <%= Rails.configuration.user_password %> terms_and_conditions_agreed_at: <%= 1.minute.ago %> confirmed_at: <%= 1.minute.ago %> first_name: Demo diff --git a/lib/tasks/eyfs.rake b/lib/tasks/eyfs.rake index 01dbdba68..d03212ddf 100644 --- a/lib/tasks/eyfs.rake +++ b/lib/tasks/eyfs.rake @@ -9,7 +9,7 @@ namespace :eyfs do unless User.find_by(email: "#{bot_token}@example.com") User.create!( email: "#{bot_token}@example.com", - password: ENV.fetch('USER_PASSWORD', 'Str0ngPa$$w0rd'), + password: Rails.configuration.user_password, confirmed_at: Time.zone.now, terms_and_conditions_agreed_at: Time.zone.now, first_name: 'Bot', diff --git a/spec/config_spec.rb b/spec/config_spec.rb index d4a6fa254..ae9d71193 100644 --- a/spec/config_spec.rb +++ b/spec/config_spec.rb @@ -35,6 +35,15 @@ expect(config.dashboard_update_interval).to eq '0 0 * * *' end + it 'sets password for seeds' do + expect(config.user_password).to eq 'Str0ngPa$$word12' + + seeds = (Dibber::Seeder.seed(:user, name_method: :email)).count + users = User.count + + expect(seeds).to eq(users) + end + describe 'time out' do it 'sets interval in minutes' do expect(config.user_timeout_minutes).to eq 25 diff --git a/ui/pages/sign_in.rb b/ui/pages/sign_in.rb index 18e141b34..964f446f0 100644 --- a/ui/pages/sign_in.rb +++ b/ui/pages/sign_in.rb @@ -16,7 +16,7 @@ def with_email_and_password(email = nil, password = nil) wait_until_header_visible email ||= 'completed@example.com' - password ||= ENV.fetch('USER_PASSWORD', 'Str0ngPa$$w0rd') + password ||= Rails.configuration.user_password email_field.set(email) password_field.set(password) From b935d3c8d3a480620c5861fd910b52cf910d1d24 Mon Sep 17 00:00:00 2001 From: Katherine Martin <78093815+martikat@users.noreply.github.com> Date: Mon, 11 Dec 2023 08:47:56 +0000 Subject: [PATCH 3/5] Update to test based on PR comment --- spec/config_spec.rb | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/spec/config_spec.rb b/spec/config_spec.rb index ae9d71193..11ab11f37 100644 --- a/spec/config_spec.rb +++ b/spec/config_spec.rb @@ -31,17 +31,22 @@ expect(config.internal_mailbox).to eq 'child-development.training@education.gov.uk' end + it 'sets password for seeds' do + expect(config.user_password).to eq 'Str0ngPa$$word12' + end + it 'exports dashboard statistics daily at midnight' do expect(config.dashboard_update_interval).to eq '0 0 * * *' end - it 'sets password for seeds' do - expect(config.user_password).to eq 'Str0ngPa$$word12' - - seeds = (Dibber::Seeder.seed(:user, name_method: :email)).count - users = User.count + describe 'seeded users' do + before do + Dibber::Seeder.seed(:user, name_method: :email) + end - expect(seeds).to eq(users) + specify do + expect(User.count).to eq 3 + end end describe 'time out' do From 9fd3372457ebd670cf97db77d63e0b1325d2d60e Mon Sep 17 00:00:00 2001 From: Katherine Martin <78093815+martikat@users.noreply.github.com> Date: Fri, 15 Dec 2023 13:14:30 +0000 Subject: [PATCH 4/5] Update password where it is used to be updated version --- spec/controllers/user_controller_spec.rb | 4 ++-- spec/factories/users.rb | 2 +- spec/system/registered_user/changing_password_spec.rb | 4 ++-- spec/system/sign_in_spec.rb | 2 +- ui/pages/sign_in.rb | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/spec/controllers/user_controller_spec.rb b/spec/controllers/user_controller_spec.rb index 358ddfc94..e5e08691a 100644 --- a/spec/controllers/user_controller_spec.rb +++ b/spec/controllers/user_controller_spec.rb @@ -54,7 +54,7 @@ { password: 'NewPassword12!@', confirm_password: 'NewPassword12!@', - current_password: 'Str0ngPa$$w0rd', + current_password: 'Str0ngPa$$w0rd12', } end @@ -90,7 +90,7 @@ { password: '', confirm_password: '', - current_password: 'Str0ngPa$$w0rd', + current_password: 'Str0ngPa$$w0rd12', } end diff --git a/spec/factories/users.rb b/spec/factories/users.rb index 2b339dee9..d5d1f4531 100644 --- a/spec/factories/users.rb +++ b/spec/factories/users.rb @@ -1,7 +1,7 @@ FactoryBot.define do factory :user do email { Faker::Internet.email } - password { 'Str0ngPa$$w0rd' } + password { 'Str0ngPa$$w0rd12' } terms_and_conditions_agreed_at { Date.new(2000, 0o1, 0o1) } trait :confirmed do diff --git a/spec/system/registered_user/changing_password_spec.rb b/spec/system/registered_user/changing_password_spec.rb index 47679ba47..1a43de4aa 100644 --- a/spec/system/registered_user/changing_password_spec.rb +++ b/spec/system/registered_user/changing_password_spec.rb @@ -3,13 +3,13 @@ RSpec.describe 'Registered user changing password', type: :system do subject(:user) { create :user, :registered, created_at: 1.month.ago } - let(:password) { 'Str0ngPa$$w0rd' } + let(:password) { 'Str0ngPa$$w0rd12' } include_context 'with user' before do visit '/my-account/edit-password' - fill_in 'Enter your current password', with: 'Str0ngPa$$w0rd' + fill_in 'Enter your current password', with: 'Str0ngPa$$w0rd12' fill_in 'Create a new password', with: password fill_in 'Confirm password', with: password end diff --git a/spec/system/sign_in_spec.rb b/spec/system/sign_in_spec.rb index a55ae8c2c..311d60617 100644 --- a/spec/system/sign_in_spec.rb +++ b/spec/system/sign_in_spec.rb @@ -2,7 +2,7 @@ RSpec.describe 'Sign in' do let(:email_address) { user.email } - let(:password) { 'Str0ngPa$$w0rd' } + let(:password) { 'Str0ngPa$$w0rd12' } before do visit '/users/sign-in' diff --git a/ui/pages/sign_in.rb b/ui/pages/sign_in.rb index 964f446f0..d960d6fcc 100644 --- a/ui/pages/sign_in.rb +++ b/ui/pages/sign_in.rb @@ -11,7 +11,7 @@ class SignIn < Base # Authenticate using email and password # # @param email [String] login email address (default: completed@example.com) - # @param password [String] login password (default: Str0ngPa$$w0rd) + # @param password [String] login password (default: Str0ngPa$$w0rd12) def with_email_and_password(email = nil, password = nil) wait_until_header_visible From cfd812aa4cd344fcbd03b70660f5dda11a76ae55 Mon Sep 17 00:00:00 2001 From: Katherine Martin <78093815+martikat@users.noreply.github.com> Date: Wed, 20 Dec 2023 11:05:38 +0000 Subject: [PATCH 5/5] Update to use user password config based on PR comments --- config/application.rb | 2 +- spec/config_spec.rb | 2 +- spec/factories/users.rb | 2 +- spec/system/registered_user/changing_password_spec.rb | 2 +- spec/system/sign_in_spec.rb | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/config/application.rb b/config/application.rb index 2fe90adbc..c23062f67 100644 --- a/config/application.rb +++ b/config/application.rb @@ -59,7 +59,7 @@ class Application < Rails::Application config.user_timeout_warning_minutes = ENV.fetch('TIMEOUT_WARNING_MINUTES', '20').to_i config.user_timeout_modal_visible = ENV.fetch('TIMEOUT_MODAL_VISIBLE', '5').to_i - config.user_password = ENV.fetch('USER_PASSWORD', 'Str0ngPa$$word12') + config.user_password = ENV.fetch('USER_PASSWORD', 'Str0ngPa$$w0rd12') # Contentful config.contentful_space = ENV.fetch('CONTENTFUL_SPACE', credentials.dig(:contentful, :space)) diff --git a/spec/config_spec.rb b/spec/config_spec.rb index 11ab11f37..8c7726803 100644 --- a/spec/config_spec.rb +++ b/spec/config_spec.rb @@ -32,7 +32,7 @@ end it 'sets password for seeds' do - expect(config.user_password).to eq 'Str0ngPa$$word12' + expect(config.user_password).to eq 'Str0ngPa$$w0rd12' end it 'exports dashboard statistics daily at midnight' do diff --git a/spec/factories/users.rb b/spec/factories/users.rb index d5d1f4531..e4a323106 100644 --- a/spec/factories/users.rb +++ b/spec/factories/users.rb @@ -1,7 +1,7 @@ FactoryBot.define do factory :user do email { Faker::Internet.email } - password { 'Str0ngPa$$w0rd12' } + password { Rails.configuration.user_password } terms_and_conditions_agreed_at { Date.new(2000, 0o1, 0o1) } trait :confirmed do diff --git a/spec/system/registered_user/changing_password_spec.rb b/spec/system/registered_user/changing_password_spec.rb index 1a43de4aa..8870164c0 100644 --- a/spec/system/registered_user/changing_password_spec.rb +++ b/spec/system/registered_user/changing_password_spec.rb @@ -3,7 +3,7 @@ RSpec.describe 'Registered user changing password', type: :system do subject(:user) { create :user, :registered, created_at: 1.month.ago } - let(:password) { 'Str0ngPa$$w0rd12' } + let(:password) { 'Str0ngPa$$w0rd13' } include_context 'with user' diff --git a/spec/system/sign_in_spec.rb b/spec/system/sign_in_spec.rb index 311d60617..2a235da7c 100644 --- a/spec/system/sign_in_spec.rb +++ b/spec/system/sign_in_spec.rb @@ -2,7 +2,7 @@ RSpec.describe 'Sign in' do let(:email_address) { user.email } - let(:password) { 'Str0ngPa$$w0rd12' } + let(:password) { Rails.configuration.user_password } before do visit '/users/sign-in'