Skip to content

Commit

Permalink
Modernize tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
demiankatz committed Jan 3, 2024
1 parent 473fe1d commit 4968398
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[
{
"comment": "simulate bad token",
"expectedPath": "/users",
"status": 400
},
{
"comment": "send new token",
"expectedMethod": "POST",
"expectedPath": "/authn/login",
"expectedParams": "{\"tenant\":\"legacy_tenant\",\"username\":\"config_username\",\"password\":\"config_password\"}",
"headers": { "X-Okapi-Token": "x-okapi-token-after-invalid" }
},
{
"comment": "confirm that new token is used",
"expectedPath": "/service-points",
"expectedHeaders": { "X-Okapi-Token": "x-okapi-token-after-invalid" },
"expectedParams": {
"query": "pickupLocation=true",
"offset": 0,
"limit": 1000
},
"body": "{ \"servicepoints\": [] }"
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
{
"comment": "send new token",
"expectedMethod": "POST",
"expectedPath": "/authn/login",
"expectedPath": "/authn/login-with-expiry",
"expectedParams": "{\"tenant\":\"config_tenant\",\"username\":\"config_username\",\"password\":\"config_password\"}",
"headers": { "X-Okapi-Token": "x-okapi-token-after-invalid" }
"headers": { "Set-Cookie": "folioAccessToken=x-okapi-token-after-invalid; Max-Age=600; Expires=Fri, 22 Sep 2023 14:30:10 GMT; Path=/; Secure; HTTPOnly; SameSite=None" }
},
{
"comment": "confirm that new token is used",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[
{
"comment": "Initial request for token",
"expectedMethod": "POST",
"expectedParams": "{\"tenant\":\"legacy_tenant\",\"username\":\"config_username\",\"password\":\"config_password\"}",
"expectedPath": "/authn/login",
"expectedHeaders": { "X-Okapi-Tenant": "legacy_tenant" },
"headers": { "X-Okapi-Token": "x-okapi-token-config-tenant" }
},
{
"expectedPath": "/users",
"expectedParams": { "query": "id == \"whatever\"" },
"expectedHeaders": { "X-Okapi-Token": "x-okapi-token-config-tenant" },
"body": "{ \"users\": [ { \"id\": \"id\" } ] }"
}
]
16 changes: 0 additions & 16 deletions module/VuFind/tests/fixtures/folio/responses/get-tokens-rtr.json

This file was deleted.

4 changes: 2 additions & 2 deletions module/VuFind/tests/fixtures/folio/responses/get-tokens.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"comment": "Initial request for token",
"expectedMethod": "POST",
"expectedParams": "{\"tenant\":\"config_tenant\",\"username\":\"config_username\",\"password\":\"config_password\"}",
"expectedPath": "/authn/login",
"expectedPath": "/authn/login-with-expiry",
"expectedHeaders": { "X-Okapi-Tenant": "config_tenant" },
"headers": { "X-Okapi-Token": "x-okapi-token-config-tenant" }
"headers": { "Set-Cookie": "folioAccessToken=x-okapi-token-config-tenant; Max-Age=600; Expires=Fri, 22 Sep 2023 14:30:10 GMT; Path=/; Secure; HTTPOnly; SameSite=None" }
},
{
"expectedPath": "/users",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[
{
"comment": "Initial token check"
},
{
"comment": "login attempt",
"expectedMethod": "POST",
"expectedPath": "/authn/login",
"expectedParams": "{\"tenant\":\"legacy_tenant\",\"username\":\"foo\",\"password\":\"bar\"}"
},
{
"comment": "profile retrieval",
"expectedPath": "/users",
"expectedParams": {
"query": "username == foo"
},
"body": "{ \"users\": [ { \"id\": \"fake-id\", \"personal\": { \"firstName\": \"first\", \"lastName\": \"last\", \"email\": \"fake@fake.com\" } } ] }"
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
"comment": "login attempt",
"expectedMethod": "POST",
"expectedPath": "/authn/login",
"expectedPath": "/authn/login-with-expiry",
"expectedParams": "{\"tenant\":\"config_tenant\",\"username\":\"foo\",\"password\":\"bar\"}"
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

/**
* ILS driver test
* FOLIO ILS driver test
*
* PHP version 8
*
* Copyright (C) Villanova University 2011.
* Copyright (C) Villanova University 2011-2024.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
Expand Down Expand Up @@ -34,7 +34,7 @@
use VuFind\ILS\Driver\Folio;

/**
* ILS driver test
* FOLIO ILS driver test
*
* @category VuFind
* @package Tests
Expand All @@ -58,7 +58,6 @@ class FolioTest extends \PHPUnit\Framework\TestCase
'tenant' => 'config_tenant',
'username' => 'config_username',
'password' => 'config_password',
'legacy_authentication' => 'true',
],
];

Expand Down Expand Up @@ -191,14 +190,9 @@ protected function createConnector(string $test, array $config = null): void
*
* @return void
*/
public function testTokensWithExpiry(): void
public function testTokens(): void
{
// Take default configuration, but use a different tenant (to avoid
// session collision with other tests) and disable legacy authentication:
$config = $this->defaultDriverConfig;
$config['API']['tenant'] = 'rtr_tenant';
$config['API']['legacy_authentication'] = 0;
$this->createConnector('get-tokens-rtr', $config); // saves to $this->driver
$this->createConnector('get-tokens'); // saves to $this->driver
$this->driver->getMyProfile(['id' => 'whatever']);
}

Expand All @@ -207,9 +201,14 @@ public function testTokensWithExpiry(): void
*
* @return void
*/
public function testTokens(): void
public function testTokensWithLegacyAuth(): void
{
$this->createConnector('get-tokens'); // saves to $this->driver
// Take default configuration, but use a different tenant (to avoid
// session collision with other tests) and disable legacy authentication:
$config = $this->defaultDriverConfig;
$config['API']['tenant'] = 'legacy_tenant';
$config['API']['legacy_authentication'] = 1;
$this->createConnector('get-tokens-legacy', $config); // saves to $this->driver
$this->driver->getMyProfile(['id' => 'whatever']);
}

Expand All @@ -225,7 +224,7 @@ public function testCheckValidToken(): void
}

/**
* Check and renew an invalid token retrieved from session cache
* Check and renew an invalid token retrieved from session cache (RTR authentication)
*
* @return void
*/
Expand All @@ -235,6 +234,22 @@ public function testCheckInvalidToken(): void
$this->driver->getPickupLocations(['username' => 'whatever']);
}

/**
* Check and renew an invalid token retrieved from session cache (legacy authentication)
*
* @return void
*/
public function testCheckInvalidTokenLegacyAuth(): void
{
// Take default configuration, but use a different tenant (to avoid
// session collision with other tests) and disable legacy authentication:
$config = $this->defaultDriverConfig;
$config['API']['tenant'] = 'legacy_tenant';
$config['API']['legacy_authentication'] = 1;
$this->createConnector('check-invalid-token-legacy', $config);
$this->driver->getPickupLocations(['username' => 'whatever']);
}

/**
* Confirm that cancel holds validates the current patron.
*
Expand Down Expand Up @@ -283,7 +298,7 @@ public function testUnsuccessfulPatronLogin(): void
}

/**
* Test patron login with Okapi
* Test patron login with Okapi (RTR authentication)
*
* @return void
*/
Expand All @@ -306,6 +321,33 @@ public function testSuccessfulPatronLoginWithOkapi(): void
$this->assertEquals($expected, $result);
}

/**
* Test patron login with Okapi (Legacy authentication)
*
* @return void
*/
public function testSuccessfulPatronLoginWithOkapiLegacyAuth(): void
{
$config = $this->defaultDriverConfig;
$config['API']['tenant'] = 'legacy_tenant';
$config['API']['legacy_authentication'] = 1;
$this->createConnector(
'successful-patron-login-with-okapi-legacy',
$config + ['User' => ['okapi_login' => true]]
);
$result = $this->driver->patronLogin('foo', 'bar');
$expected = [
'id' => 'fake-id',
'username' => 'foo',
'cat_username' => 'foo',
'cat_password' => 'bar',
'firstname' => 'first',
'lastname' => 'last',
'email' => 'fake@fake.com',
];
$this->assertEquals($expected, $result);
}

/**
* Test successful place hold
*
Expand Down

0 comments on commit 4968398

Please sign in to comment.