Bugzilla – Attachment 61684 Details for
Bug 12026
Shibboleth auto-provisioning - Create
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 12026: [QA Follow-up] Add Tests for autocreate
Bug-12026-QA-Follow-up-Add-Tests-for-autocreate.patch (text/plain), 7.51 KB, created by
Olli-Antti Kivilahti
on 2017-03-29 14:36:19 UTC
(
hide
)
Description:
Bug 12026: [QA Follow-up] Add Tests for autocreate
Filename:
MIME Type:
Creator:
Olli-Antti Kivilahti
Created:
2017-03-29 14:36:19 UTC
Size:
7.51 KB
patch
obsolete
>From 1a2ded7f521580524fa4f8fe57c32eef3fb1c1d0 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Thu, 23 Mar 2017 14:54:38 +0000 >Subject: [PATCH] Bug 12026: [QA Follow-up] Add Tests for autocreate > >https://bugs.koha-community.org/show_bug.cgi?id=12026 >Signed-off-by: Olli-Antti Kivilahti <olli-antti.kivilahti@jns.fi> >--- > t/Auth_with_shibboleth.t | 153 ++++++++++++++++++++++++++++++++--------------- > 1 file changed, 104 insertions(+), 49 deletions(-) > >diff --git a/t/Auth_with_shibboleth.t b/t/Auth_with_shibboleth.t >index 33110c4..ab03248 100644 >--- a/t/Auth_with_shibboleth.t >+++ b/t/Auth_with_shibboleth.t >@@ -38,8 +38,21 @@ use Test::DBIx::Class; > > # Mock Variables > my $matchpoint = 'userid'; >-my %mapping = ( 'userid' => { 'is' => 'uid' }, ); >-$ENV{'uid'} = "test1234"; >+my $autocreate = 0; >+my %mapping = ( >+ 'userid' => { 'is' => 'uid' }, >+ 'surname' => { 'is' => 'sn' }, >+ 'dateexpiry' => { 'is' => 'exp' }, >+ 'categorycode' => { 'is' => 'cat' }, >+ 'address' => { 'is' => 'add' }, >+ 'city' => { 'is' => 'city' }, >+); >+$ENV{'uid'} = "test1234"; >+$ENV{'sn'} = undef; >+$ENV{'exp'} = undef; >+$ENV{'cat'} = undef; >+$ENV{'add'} = undef; >+$ENV{'city'} = undef; > > # Setup Mocks > ## Mock Context >@@ -48,51 +61,16 @@ my $context = new Test::MockModule('C4::Context'); > ### Mock ->config > $context->mock( 'config', \&mockedConfig ); > >-sub mockedConfig { >- my $param = shift; >- >- my %shibboleth = ( >- 'matchpoint' => $matchpoint, >- 'mapping' => \%mapping >- ); >- >- return \%shibboleth; >-} >- > ### Mock ->preference > my $OPACBaseURL = "testopac.com"; > $context->mock( 'preference', \&mockedPref ); > >-sub mockedPref { >- my $param = $_[1]; >- my $return; >- >- if ( $param eq 'OPACBaseURL' ) { >- $return = $OPACBaseURL; >- } >- >- return $return; >-} >- > ## Mock Database > my $database = new Test::MockModule('Koha::Database'); > > ### Mock ->schema > $database->mock( 'schema', \&mockedSchema ); > >-sub mockedSchema { >- return Schema(); >-} >- >-## Convenience method to reset config >-sub reset_config { >- $matchpoint = 'userid'; >- %mapping = ( 'userid' => { 'is' => 'uid' }, ); >- $ENV{'uid'} = "test1234"; >- >- return 1; >-} >- > # Tests > ############################################################## > >@@ -175,7 +153,7 @@ subtest "get_login_shib tests" => sub { > > ## checkpw_shib > subtest "checkpw_shib tests" => sub { >- plan tests => 13; >+ plan tests => 18; > > my $shib_login; > my ( $retval, $retcard, $retuserid ); >@@ -186,6 +164,7 @@ subtest "checkpw_shib tests" => sub { > [qw/cardnumber userid surname address city/], > [qw/testcardnumber test1234 renvoize myaddress johnston/], > ], >+ 'Category' => [ [qw/categorycode default_privacy/], [qw/S never/], ] > ], > 'Installed some custom fixtures via the Populate fixture class'; > >@@ -195,7 +174,7 @@ subtest "checkpw_shib tests" => sub { > # good user > $shib_login = "test1234"; > warnings_are { >- ( $retval, $retcard, $retuserid ) = checkpw_shib( $shib_login ); >+ ( $retval, $retcard, $retuserid ) = checkpw_shib($shib_login); > } > [], "good user with no debug"; > is( $retval, "1", "user authenticated" ); >@@ -205,22 +184,47 @@ subtest "checkpw_shib tests" => sub { > # bad user > $shib_login = 'martin'; > warnings_are { >- ( $retval, $retcard, $retuserid ) = checkpw_shib( $shib_login ); >+ ( $retval, $retcard, $retuserid ) = checkpw_shib($shib_login); > } > [], "bad user with no debug"; > is( $retval, "0", "user not authenticated" ); > >+ # autocreate user >+ $autocreate = 1; >+ $shib_login = 'test4321'; >+ $ENV{'uid'} = 'test4321'; >+ $ENV{'sn'} = "pika"; >+ $ENV{'exp'} = "2017"; >+ $ENV{'cat'} = "S"; >+ $ENV{'add'} = 'Address'; >+ $ENV{'city'} = 'City'; >+ warnings_are { >+ ( $retval, $retcard, $retuserid ) = checkpw_shib($shib_login); >+ } >+ [], "new user added with no debug"; >+ is( $retval, "1", "user authenticated" ); >+ is( $retuserid, "test4321", "expected userid returned" ); >+ ok my $new_user = ResultSet('Borrower') >+ ->search( { 'userid' => 'test4321' }, { rows => 1 } ), "new user found"; >+ is_fields [qw/surname dateexpiry address city/], $new_user->next, >+ [qw/pika 2017 Address City/], >+ 'Found $new_users surname'; >+ $autocreate = 0; >+ > # debug on > $C4::Auth_with_shibboleth::debug = '1'; > > # good user > $shib_login = "test1234"; > warnings_exist { >- ( $retval, $retcard, $retuserid ) = checkpw_shib( $shib_login ); >+ ( $retval, $retcard, $retuserid ) = checkpw_shib($shib_login); > } >- [ qr/checkpw_shib/, qr/koha borrower field to match: userid/, >- qr/shibboleth attribute to match: uid/, >- qr/User Shibboleth-authenticated as:/ ], >+ [ >+ qr/checkpw_shib/, >+ qr/koha borrower field to match: userid/, >+ qr/shibboleth attribute to match: uid/, >+ qr/User Shibboleth-authenticated as:/ >+ ], > "good user with debug enabled"; > is( $retval, "1", "user authenticated" ); > is( $retcard, "testcardnumber", "expected cardnumber returned" ); >@@ -229,7 +233,7 @@ subtest "checkpw_shib tests" => sub { > # bad user > $shib_login = "martin"; > warnings_exist { >- ( $retval, $retcard, $retuserid ) = checkpw_shib( $shib_login ); >+ ( $retval, $retcard, $retuserid ) = checkpw_shib($shib_login); > } > [ > qr/checkpw_shib/, >@@ -251,8 +255,8 @@ is( C4::Auth_with_shibboleth::_get_uri(), > $OPACBaseURL = "http://testopac.com"; > my $result; > warning_like { $result = C4::Auth_with_shibboleth::_get_uri() } >- [ qr/Shibboleth requires OPACBaseURL to use the https protocol!/ ], >- "improper protocol - received expected warning"; >+[qr/Shibboleth requires OPACBaseURL to use the https protocol!/], >+ "improper protocol - received expected warning"; > is( $result, "https://testopac.com", "https opac uri returned" ); > > $OPACBaseURL = "https://testopac.com"; >@@ -261,9 +265,60 @@ is( C4::Auth_with_shibboleth::_get_uri(), > > $OPACBaseURL = undef; > warning_like { $result = C4::Auth_with_shibboleth::_get_uri() } >- [ qr/OPACBaseURL not set!/ ], >- "undefined OPACBaseURL - received expected warning"; >+[qr/OPACBaseURL not set!/], >+ "undefined OPACBaseURL - received expected warning"; > is( $result, "https://", "https opac uri returned" ); > > ## _get_shib_config > # Internal helper function, covered in tests above >+ >+sub mockedConfig { >+ my $param = shift; >+ >+ my %shibboleth = ( >+ 'autocreate' => $autocreate, >+ 'matchpoint' => $matchpoint, >+ 'mapping' => \%mapping >+ ); >+ >+ return \%shibboleth; >+} >+ >+sub mockedPref { >+ my $param = $_[1]; >+ my $return; >+ >+ if ( $param eq 'OPACBaseURL' ) { >+ $return = $OPACBaseURL; >+ } >+ >+ return $return; >+} >+ >+sub mockedSchema { >+ return Schema(); >+} >+ >+## Convenience method to reset config >+sub reset_config { >+ $matchpoint = 'userid'; >+ $autocreate = 0; >+ %mapping = ( >+ 'userid' => { 'is' => 'uid' }, >+ 'surname' => { 'is' => 'sn' }, >+ 'dateexpiry' => { 'is' => 'exp' }, >+ 'categorycode' => { 'is' => 'cat' }, >+ 'address' => { 'is' => 'add' }, >+ 'city' => { 'is' => 'city' }, >+ ); >+ $ENV{'uid'} = "test1234"; >+ $ENV{'sn'} = undef; >+ $ENV{'exp'} = undef; >+ $ENV{'cat'} = undef; >+ $ENV{'add'} = undef; >+ $ENV{'city'} = undef; >+ >+ return 1; >+} >+ >+1; >-- >2.7.4
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 12026
:
26769
|
26788
|
28408
|
30351
|
30352
|
30376
|
31054
|
31055
|
35551
|
35552
|
56241
|
56242
|
56243
|
57486
|
57563
|
57564
|
57565
|
57566
|
61268
|
61269
|
61270
|
61271
|
61363
|
61364
|
61365
|
61366
|
61367
|
61435
|
61436
|
61437
|
61438
|
61444
|
61445
|
61446
|
61447
|
61448
|
61449
|
61521
|
61522
|
61523
|
61524
|
61525
|
61526
|
61527
|
61596
|
61598
|
61599
|
61675
|
61676
|
61677
|
61678
|
61679
|
61680
|
61683
| 61684 |
62521
|
62522