Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[API] New branch for adding the testsuite for the API + addressed comments #6671

Merged
merged 97 commits into from
Aug 27, 2020
Merged
Show file tree
Hide file tree
Changes from 91 commits
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
cc98eef
[API] New branch for adding the testsuite for the API + addressed com…
spell00 Jun 4, 2020
3f1b709
[API] New branch for adding the testsuite for the API + addressed com…
spell00 Jun 4, 2020
882deb3
[API] Remove whitespaces to pass Travis checks with no ERRORS
spell00 Jun 5, 2020
c73bd3a
[API] Each endpoints gets its own mthod for testing it. The test suit…
spell00 Jun 24, 2020
b933119
[API] Remove loops and starts adding specific tests for each endpoints
spell00 Jul 6, 2020
b5cf585
[API] LorisApiAuthenticationTest removed by mistake restored
spell00 Jul 6, 2020
215b3fa
[API] Assessments of body content
spell00 Jul 7, 2020
afb7bb3
[API] Added required modification of the JWTKey in the Config table o…
spell00 Jul 7, 2020
d52f24e
[API] Final modifications to pass Travis checks
spell00 Jul 7, 2020
3a1a74e
Change authentication request uri.
spell00 Jul 7, 2020
517b80b
[API] changed the setUp methods to call guzzleLogin()
spell00 Jul 7, 2020
8e72f7d
[API] changed the setUp methods to call guzzleLogin()
spell00 Jul 7, 2020
127d80d
[API] changed the setUp methods to call guzzleLogin()
spell00 Jul 7, 2020
4184346
SetUp changes
spell00 Jul 8, 2020
b3bcf47
[API] More corrections to the test suite
spell00 Jul 8, 2020
bae9da9
[API] More corrections to test suite
spell00 Jul 8, 2020
5782a5a
[further changes]
spell00 Jul 9, 2020
503c38b
[API] add Incomplete tests markers
spell00 Jul 9, 2020
70a6b40
[API] add Incomplete tests markers - correct travis errors
spell00 Jul 9, 2020
560c1ab
[API] add Incomplete tests markers - correct travis errors
spell00 Jul 9, 2020
c0cdef0
add Incomplete tests markers - correct travis errors
spell00 Jul 10, 2020
1c875a4
add Incomplete tests markers - correct travis errors
spell00 Jul 10, 2020
6c67095
[API] fix No tests found in class "LorisApiAuthenticatedTest"
spell00 Jul 10, 2020
64083cc
[API] fix No tests found in class "LorisApiAuthenticatedTest"
spell00 Jul 10, 2020
0e2eedd
[API] moved LorisApiAuthenticatedTest.php to tests/integrationtests
spell00 Jul 13, 2020
dbeb8cb
[API] moved LorisApiAuthenticatedTest.php to tests/integrationtests
spell00 Jul 13, 2020
a1c20e2
[API] moved LorisApiAuthenticatedTest.php to tests/integrationtests
spell00 Jul 13, 2020
c5709d1
[API] moved LorisApiAuthenticatedTest.php to tests/integrationtests
spell00 Jul 14, 2020
1ec181f
[API] Add more Exception to avoid failures and unmoved LorisApiAuthen…
spell00 Jul 14, 2020
0306162
[API] Add more Exception to avoid failures and unmoved LorisApiAuthen…
spell00 Jul 14, 2020
72e990e
[API] Remove useless skipped tests
spell00 Jul 21, 2020
f2e54d3
[API] Remove useless skipped tests
spell00 Jul 21, 2020
e2a0975
[API] Remove useless skipped tests
spell00 Jul 21, 2020
211bb11
[API] Remove useless skipped tests
spell00 Jul 21, 2020
8cff4d0
removed useless PUT & POST requests
spell00 Jul 21, 2020
9e78b29
[API] removed tests where data is missing
spell00 Jul 21, 2020
e424c85
[API] Changed invalid visits in instruments tests
spell00 Jul 21, 2020
1dda281
[API] Changed invalid visit and candid in visits tests of PUT request
spell00 Jul 21, 2020
7bdb5b8
[API] Other corrections
spell00 Jul 21, 2020
3818b77
[API] Other corrections
spell00 Jul 21, 2020
9f8df6c
[API] Other corrections
spell00 Jul 21, 2020
7bfb577
[API] Other corrections
spell00 Jul 22, 2020
9c16778
[API] Other corrections
spell00 Jul 22, 2020
57d8e97
[API] restore instruments test
spell00 Jul 22, 2020
a620d70
Added instruments to docker image
spell00 Jul 22, 2020
4860731
Added instruments to docker image
spell00 Jul 22, 2020
42e5675
[API] Add two incomplete tests
spell00 Jul 22, 2020
e0db8b4
[API] Add two incomplete tests
spell00 Jul 22, 2020
425133a
[API] Add two incomplete tests
spell00 Jul 22, 2020
feb19d6
[API] Removed Visit test put endpoint because user has no permission …
spell00 Jul 23, 2020
dd3bc8c
[API] last corrections before ready for review
spell00 Jul 23, 2020
c4ca6f4
[API] Removed more useless code to catch errors
spell00 Jul 24, 2020
f724f1c
[API] Changed projectIdTest to projectName
spell00 Jul 24, 2020
f517323
testGetProjectsProjectInstrumentsInstrument is not found, changing to…
spell00 Jul 24, 2020
f66b1b7
Fixing candidates tests
spell00 Jul 30, 2020
e8b58be
[API] Rebasing
spell00 Jul 30, 2020
5f3851e
[API] Fixing Travis build - npm package babel/core dependency error w…
spell00 Jul 30, 2020
5629cc1
[API] Remove useless comment and assertion of variables with NULL values
spell00 Aug 3, 2020
db21363
[API] remove unnecessary try catch and remove 2 raisinbread files fro…
spell00 Aug 12, 2020
c7f9b74
[API] restoring to previous commit
spell00 Aug 13, 2020
becb72f
[API] Correct typos, remove useless setUps and tearDowns and JWTKey c…
spell00 Aug 17, 2020
30bd840
[API] JWTKey change in dockerfile.test.db
spell00 Aug 17, 2020
58bbe30
[API] Changed update of table Config
spell00 Aug 18, 2020
c0759ce
[API] correct Travis and remove code left behind
spell00 Aug 18, 2020
b491a6e
[API] Make valid JWT key
spell00 Aug 18, 2020
5b5be20
[API] Make valid JWT key
spell00 Aug 18, 2020
951f1a5
[API] Make valid JWT key
spell00 Aug 18, 2020
b784f8c
[API] Make valid JWT key
spell00 Aug 18, 2020
07444ad
[API] Make valid JWT key
spell00 Aug 18, 2020
5e5ef32
[API] Make valid JWT key
spell00 Aug 18, 2020
47db56a
[API] Make valid JWT key
spell00 Aug 18, 2020
e6b73cb
Modif JWT key in db during test
spell00 Aug 18, 2020
4465fec
[API] Fix ofd typo and orthograph correction
spell00 Aug 18, 2020
c6f530b
Remove useless comment left behind
spell00 Aug 19, 2020
69c8a3e
[API] Moved the integration test suite from modules/api/test to raisi…
spell00 Aug 19, 2020
6a75623
JWT key was not modified properly
spell00 Aug 19, 2020
dd6ae3c
really make JWT key valid
spell00 Aug 19, 2020
8b192eb
really make JWT key valid
spell00 Aug 20, 2020
a19b64e
really make JWT key valid
spell00 Aug 20, 2020
5e496f6
really make JWT key valid
spell00 Aug 20, 2020
cc04f08
JWT key original value was not restored correctly
spell00 Aug 20, 2020
c299765
fixed bad indentation
spell00 Aug 20, 2020
3083a53
Declare protected configIdJwt
spell00 Aug 20, 2020
cb49b46
[API] more cleanup
spell00 Aug 20, 2020
a16fd2c
[API] changing the JWT key in LorisApiAuthenticatedTest.php
spell00 Aug 24, 2020
8402e90
[API] code deleted in LorisApiAuthenticatedTest.php
spell00 Aug 24, 2020
a03e607
[API] changes in LorisApiAuthenticatedTest setUp for setting valid JW…
spell00 Aug 24, 2020
de48807
[API] removing any changes made to LorisIntegrationTest.class.inc
spell00 Aug 24, 2020
88d699d
[API] Throws exception when no config for JWT key
spell00 Aug 24, 2020
1ce75cd
[API] Throws exception when no config for JWT key
spell00 Aug 24, 2020
e4e2460
[API] Renaming login in API test suite apiLogin
spell00 Aug 24, 2020
6510dda
Correcting indentation
spell00 Aug 24, 2020
3e29f39
Correct indentation
spell00 Aug 24, 2020
8fd8394
[API] updates the doc of setUp and tearDown to include modifications …
spell00 Aug 24, 2020
0a3f7f1
[API] Improves the description of setUp and tearDown functions in Lor…
spell00 Aug 25, 2020
f19c41f
[skip ci] Fixing the documentation of tearDown
spell00 Aug 25, 2020
ff8d144
Fixing other typos and indentation
spell00 Aug 25, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,23 @@
},
"devDependencies": {
"@babel/cli": "^7.6.4",
"@babel/core": "^7.6.4",
"@babel/core": "^7.11.0",
spell00 marked this conversation as resolved.
Show resolved Hide resolved
"@babel/plugin-proposal-object-rest-spread": "^7.6.2",
"@babel/preset-env": "^7.6.3",
"@babel/preset-react": "^7.6.3",
"c3": "^0.7.15",
"d3": "^5.15.0",
"css-loader": "^3.4.2",
"alex": ">=8.0.1",
"babel-eslint": "^10.0.1",
"babel-loader": "^8.0.5",
"c3": "^0.7.15",
"css-loader": "^3.4.2",
"d3": "^5.15.0",
"eslint": "^5.16.0",
"eslint-config-google": "0.9.1",
"eslint-loader": "^2.2.1",
"eslint-plugin-react": "^7.16.0",
"terser-webpack-plugin": "^1.3.0",
"webpack": "^4.41.2",
"webpack-cli": "^3.3.0",
"alex": ">=8.0.1"
"webpack-cli": "^3.3.0"
},
"scripts": {
"lint:javascript": "./test/run-js-linter.sh",
Expand Down
141 changes: 141 additions & 0 deletions raisinbread/test/api/LorisApiAuthenticatedTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
<?php

require_once __DIR__ .
"/../../../test/integrationtests/LorisIntegrationTest.class.inc";
use GuzzleHttp\Client;

/**
* PHPUnit class for API test suite. This script sends HTTP requests to every
* endpoints of the api module and look at the response content, status code and
* headers where it applies. All endpoints are accessible at <host>/api/<version>/
* (e.g. the endpoint of the version 0.0.3 of the API "/projects" URI for the host
* "example.loris.ca" would be https://example.loris.ca/api/v0.0.3/projects)
*
* @category API
* @package Tests
* @subpackage Integration
* @author Simon Pelletier <simon.pelletier@mcin.ca>
* @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3
* @link https://www.github.com/aces/Loris/
*/
class LorisApiAuthenticatedTest extends LorisIntegrationTest
{

protected $client;
protected $headers;
protected $base_uri;
protected $originalJwtKey;
protected $configIdJwt;

/**
* Call to LorisApiAuthenticationTest::setUp()
*
* @return void
*/
public function setUp()
{
parent::setUp();
// store the original JWT key for restoring it later
$jwtConfig = $this->DB->pselect(
spell00 marked this conversation as resolved.
Show resolved Hide resolved
'
SELECT
Value, ConfigID
FROM
Config
WHERE
ConfigID=
(SELECT ID FROM ConfigSettings WHERE Name="JWTKey")',
[]
)[0] ?? null;

if ($jwtConfig === null) {
throw new \LorisException('There is no Config for "JWTKey"');
}

$this->originalJwtKey = $jwtConfig['Value'];
$this->configIdJwt = $jwtConfig['ConfigID'];

// generating a random JWTkey
$new_id = bin2hex(random_bytes(30)) . 'A1!';

$set = [
'Value' => $new_id
];

$where = [
'ConfigID' => $this->configIdJwt
];

$this->DB->update('Config', $set, $where);

$this->apiLogin('UnitTester', $this->validPassword);
}

/**
* Used to log in with GuzzleHttp\Client
*
* @param string $username The username to log in as
* @param string $password The (plain text) password to login as.
*
* @return void
*/
public function apiLogin($username, $password)
{
$this->base_uri = "$this->url/api/v0.0.3/";
$this->client = new Client(['base_uri' => $this->base_uri]);
$response = $this->client->request(
'POST',
"login",
[
'json' => ['username' => $username,
'password' => $password
]
]
);
$this->assertEquals(200, $response->getStatusCode());
$token = json_decode(
$response->getBody()->getContents()
)->token ?? null;

if ($token === null) {
throw new \LorisException("Login failed");
}
$headers = [
'Authorization' => "Bearer $token",
'Accept' => 'application/json'
];
$this->headers = $headers;
}

/**
* Used to test login
*
* @return void
*/
function testLoginSuccess()
{
$this->assertArrayHasKey('Authorization', $this->headers);
$this->assertArrayHasKey('Accept', $this->headers);
}

/**
* Call to LorisApiAuthenticationTest::tearDown()
*
* @return void
*/
public function tearDown()
{
$set = [
'Value' => $this->originalJwtKey
];

$where = [
'ConfigID' => $this->configIdJwt
];

$this->DB->update('Config', $set, $where);
parent::tearDown();
}

}

Loading