Skip to content

Commit 6edce74

Browse files
committed
Add tests for access control and setup users for testing
1 parent 3658a2a commit 6edce74

File tree

4 files changed

+47
-2
lines changed

4 files changed

+47
-2
lines changed

db/seeds/support/person_seeder.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ def seed_people(names)
1919
seed_project_technology(project.id)
2020
end
2121
end
22+
23+
# Allow the default logged-in user to edit themselves
24+
Person.find_by_name("Carl Albrecht Conf Admin")&.update(auth_user_id: 1)
2225
end
2326

2427
def seed_association(assoc_name, person_id)

spec/features/people_spec.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,4 +379,29 @@ def add_language(language)
379379
expect(page).to have_no_content(t("people.index.profile"))
380380
end
381381
end
382+
383+
describe 'Access control' do
384+
before(:each) do
385+
sign_in auth_users(:user)
386+
end
387+
388+
it 'logged in person can edit their own profile' do
389+
ursula = people(:user)
390+
visit person_path(ursula)
391+
392+
click_link('Bearbeiten', href: edit_person_path(ursula))
393+
fill_in 'person_title', with: 'Expert at access control'
394+
save_button = find_button("Person aktualisieren")
395+
save_button.click
396+
397+
expect(page).to have_content('Expert at access control')
398+
end
399+
400+
it 'logged in person should no be able to edit other profiles' do
401+
longmax = people(:longmax)
402+
visit person_path(longmax)
403+
404+
expect{ click_link('Bearbeiten', href: edit_person_path(longmax)) }.to raise_error("You are not authorized to access this page.")
405+
end
406+
end
382407
end

spec/fixtures/auth_users.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ user:
44
email: user@skills.ch
55
is_admin: false
66

7-
87
admin:
98
uid: 1234-5678-9012-3457
109
name: Andreas Admin

spec/fixtures/people.yml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,4 +182,22 @@ maximillian:
182182
Figma
183183
display_competence_notes_in_cv: false
184184
email: maximillian@example.com
185-
department: mid
185+
department: mid
186+
187+
user:
188+
birthdate: 1995-05-32 16:04:56
189+
location: Belp
190+
marital_status: <%= Person.marital_statuses[:single] %>
191+
name: Ursula User
192+
nationality: CH
193+
roles: [ software-engineer ]
194+
title: Just a user
195+
competence_notes: |
196+
Python
197+
Go
198+
Unity
199+
company: firma
200+
email: user@example.com
201+
department: dev-one
202+
shortname: UU
203+
auth_user_id: 227792459

0 commit comments

Comments
 (0)