Bugzilla – Attachment 157683 Details for
Bug 29523
Add a way to prevent embedding objects that should not be allowed
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 29523: (follow-up) Comprehensive tests for redaction
Bug-29523-follow-up-Comprehensive-tests-for-redact.patch (text/plain), 4.89 KB, created by
Martin Renvoize (ashimema)
on 2023-10-23 16:34:39 UTC
(
hide
)
Description:
Bug 29523: (follow-up) Comprehensive tests for redaction
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2023-10-23 16:34:39 UTC
Size:
4.89 KB
patch
obsolete
>From c3c49581aa16ee29c7c02041e471defabdf4a1b5 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Mon, 23 Oct 2023 16:19:18 +0100 >Subject: [PATCH] Bug 29523: (follow-up) Comprehensive tests for redaction > >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > t/db_dependent/Koha/Object.t | 70 +++++++++++++++++++++++++++--------- > 1 file changed, 54 insertions(+), 16 deletions(-) > >diff --git a/t/db_dependent/Koha/Object.t b/t/db_dependent/Koha/Object.t >index ecf0bed621a..035d9cddefc 100755 >--- a/t/db_dependent/Koha/Object.t >+++ b/t/db_dependent/Koha/Object.t >@@ -397,7 +397,7 @@ subtest "to_api() tests" => sub { > 'Koha::Exceptions::Object::MethodNotCoveredByTests', > 'Unknown method exception thrown if is_count not specified'; > >- subtest 'unprivileged request tests' => sub { >+ subtest 'public request tests' => sub { > > my @all_attrs = Koha::Libraries->columns(); > my $public_attrs = { map { $_ => 1 } @{ Koha::Library->public_read_list() } }; >@@ -535,16 +535,21 @@ subtest "to_api() tests" => sub { > $schema->storage->txn_rollback; > }; > >- subtest 'accessible usage tests' => sub { >+ subtest 'unprivileged requests redaction tests' => sub { > >- plan tests => 2; >+ my @all_attrs = Koha::Patrons->columns(); >+ my $unredacted_attrs = { map { $_ => 1 } @{ Koha::Patron->unredact_list() } }; >+ my $mapping = Koha::Patron->to_api_mapping; >+ my @mapped_to_null = grep { !defined( $mapping->{$_} ) } keys %{$mapping}; >+ >+ plan tests => ( scalar @all_attrs * 3 ) - scalar @mapped_to_null; > > $schema->storage->txn_begin; > > my $library_1 = $builder->build_object( { class => 'Koha::Libraries' } ); > my $library_2 = $builder->build_object( { class => 'Koha::Libraries' } ); > >- my $patron = $builder->build_object( >+ my $api_consumer = $builder->build_object( > { > class => 'Koha::Patrons', > value => { >@@ -554,20 +559,53 @@ subtest "to_api() tests" => sub { > } > ); > >- my $patron_1 = $builder->build_object( >- { class => 'Koha::Patrons', value => { branchcode => $library_1->id } } >- ); >- my $patron_2 = $builder->build_object( >- { class => 'Koha::Patrons', value => { branchcode => $library_2->id } } >- ); >+ my $patron_1 = >+ $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library_1->id } } ); >+ my $patron_2 = >+ $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library_2->id } } ); > >- t::lib::Mocks::mock_userenv( { patron => $patron } ); >+ t::lib::Mocks::mock_userenv( { patron => $api_consumer } ); > >- is( >- $patron_1->to_api( { user => $patron } )->{firstname}, $patron_1->firstname, >- 'Returns unredacted object hash' >- ); >- is( $patron_2->to_api( { user => $patron } )->{firstname}, undef, 'Returns redacted object hash' ); >+ my $visible_user = $patron_1->to_api( { user => $api_consumer } ); >+ my $redacted_user = $patron_2->to_api( { user => $api_consumer } ); >+ >+ foreach my $attr (@all_attrs) { >+ my $mapped = exists $mapping->{$attr} ? $mapping->{$attr} : $attr; >+ if ( defined($mapped) ) { >+ ok( >+ exists $visible_user->{$mapped}, >+ "Mapped attribute '$attr' is present" >+ ); >+ if ( exists $unredacted_attrs->{$attr} ) { >+ is( >+ $visible_user->{$mapped}, $patron_1->TO_JSON->{$attr}, >+ "Unredacted attribute '$attr' is visible when user is accessible" >+ ); >+ is( >+ $redacted_user->{$mapped}, $patron_2->TO_JSON->{$attr}, >+ "Unredacted attribute '$attr' is visible when user is inaccessible" >+ ); >+ } else { >+ is( >+ $visible_user->{$mapped}, $patron_1->TO_JSON->{$attr}, >+ "Redacted attribute '$attr' is visible when user is accessible" >+ ); >+ is( >+ $redacted_user->{$mapped}, undef, >+ "Redacted attribute '$attr' is undefined when user is inaccessible" >+ ); >+ } >+ } else { >+ ok( >+ !exists $visible_user->{$attr}, >+ "Mapped to null attribute '$attr' is not present when accessible" >+ ); >+ ok( >+ !exists $redacted_user->{$attr}, >+ "Mapped to null attribute '$attr' is not present when inaccessible" >+ ); >+ } >+ } > > $schema->storage->txn_rollback; > }; >-- >2.41.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 29523
:
127886
|
127887
|
127888
|
127889
|
127991
|
127992
|
127993
|
127994
|
128042
|
128043
|
128044
|
128045
|
128046
|
128047
|
128048
|
128688
|
128689
|
128690
|
128691
|
128692
|
128693
|
128694
|
131326
|
131331
|
131332
|
136684
|
136685
|
136686
|
136687
|
136688
|
136689
|
136690
|
136691
|
136692
|
136706
|
136714
|
148736
|
148737
|
148738
|
148739
|
148740
|
148741
|
148742
|
148743
|
148744
|
148745
|
150989
|
150990
|
150991
|
150992
|
150993
|
150994
|
150995
|
150996
|
150997
|
150998
|
156939
|
156940
|
156941
|
156942
|
156943
|
156944
|
156945
|
156946
|
156947
|
156948
|
156949
|
156965
|
157049
|
157071
|
157072
|
157073
|
157074
|
157075
|
157076
|
157077
|
157078
|
157079
|
157080
|
157081
|
157406
|
157407
|
157408
|
157409
|
157410
|
157411
|
157412
|
157413
|
157414
|
157415
|
157416
|
157673
|
157679
|
157683
|
157799
|
157881
|
157882
|
157883
|
157884
|
157885
|
157886
|
157887
|
157888
|
157889
|
157890
|
157891
|
157892
|
157893
|
158013