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

Fix up tests #392

Open
wants to merge 2 commits into
base: xdmod11.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use IntegrationTests\BaseTest;
use IntegrationTests\TestHarness\XdmodTestHelper;

class EfficiencyTest extends BaseTest
class EfficiencyControllerProviderTest extends BaseTest
{
const ENDPOINT = 'rest/v1/efficiency/';

Expand Down
5 changes: 2 additions & 3 deletions tests/integration/lib/REST/Warehouse/JobViewerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -408,13 +408,12 @@ public function jobTimeseriesProvider()
$ret[] = array($xdmodhelper, $searchparams, 'application/pdf', 'application/pdf; charset=binary');
$searchparams['format'] = 'csv';

$ret[] = array($xdmodhelper, $searchparams, 'text/csv;charset=UTF-8', 'application/csv; charset=us-ascii');

$ret[] = array($xdmodhelper, $searchparams, 'text/csv;charset=UTF-8', 'text/plain; charset=us-ascii');
$searchparams['format'] = 'png';
$ret[] = array($xdmodhelper, $searchparams, 'image/png', 'image/png; charset=binary');

$searchparams['format'] = 'svg';
$ret[] = array($xdmodhelper, $searchparams, 'image/svg+xml', 'image/svg+xml; charset=us-ascii');
$ret[] = array($xdmodhelper, $searchparams, 'image/svg+xml', 'image/svg; charset=us-ascii');


return $ret;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,25 @@

class DashboardSupremmTest extends TestCase
{
public function __construct($name, $data, $dataName)
const ENDPOINT = 'rest/v0.1/supremm_dataflow/';

protected static $xdmodhelper;
protected static $validateAsUser;

public static function setUpBeforeClass(): void
{
aaronweeden marked this conversation as resolved.
Show resolved Hide resolved
$xdmodConfig = array( "decodetextasjson" => true );
$this->xdmodhelper = new XdmodTestHelper($xdmodConfig);

$this->endpoint = 'rest/v0.1/supremm_dataflow/';
self::$xdmodhelper = new XdmodTestHelper($xdmodConfig);

// validate as manager, for dashboard access
$this->validateAsUser = 'mgr';
parent::__construct($name, $data, $dataName);
self::$validateAsUser = 'mgr';
}

private function invalidSupremmResourceEntries($params)
{
// without performing validation: expect to receive a 401;
// if wrong user authenticated: expect to receive a 403
$result = $this->xdmodhelper->get($this->endpoint . 'resources', $params);
$result = self::$xdmodhelper->get(self::ENDPOINT . 'resources', $params);

// expect success to be false
$this->assertArrayHasKey('success', $result[0]);
Expand All @@ -38,9 +40,9 @@ private function invalidSupremmResourceEntries($params)

private function validateSupremmResourceEntries()
{
$this->xdmodhelper->authenticate($this->validateAsUser);
self::$xdmodhelper->authenticate(self::$validateAsUser);

$result = $this->xdmodhelper->get($this->endpoint . 'resources', null);
$result = self::$xdmodhelper->get(self::ENDPOINT . 'resources', null);
$this->assertEquals(200, $result[1]['http_code']);

$this->assertArrayHasKey('success', $result[0]);
Expand Down Expand Up @@ -70,13 +72,15 @@ private function fetchResourceId()
private function invalidSupremmDbstatsEntries($db)
{
// without performing validation : expect to receive a 401
// ensure user is logged out
self::$xdmodhelper->logoutDashboard();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why logoutDashboard instead of just logout?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, because this is testing the internal dashboard. I would recommend authenticateDashboard instead of authenticate then.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So after a little bit of digging, it seems that the logout/authenticate (without Dashboard) is probably more desirable here. The authenticateDashboard does not work for these REST calls because even though they are in the internal dashboard, endpoints tested here such as supremm_dataflow/dbstats are part of the new REST stack. I need to double-check, but it seems that the {logout,authenticate}Dashboard does not properly authenticate the user for the required REST calls.


// hardcode the params for resource id
$params = array(
'resource_id' => 2791,
'db_id' => $db
);
$result = $this->xdmodhelper->get($this->endpoint . 'dbstats', $params);
$result = self::$xdmodhelper->get(self::ENDPOINT . 'dbstats', $params);

$this->assertArrayHasKey('success', $result[0]);
$this->assertFalse($result[0]['success']);
Expand All @@ -88,10 +92,10 @@ private function invalidSupremmDbstatsEntries($db)
private function invalidParamsSupremmDbstatsEntries()
{
// validate properly
$this->xdmodhelper->authenticate($this->validateAsUser);
self::$xdmodhelper->authenticate(self::$validateAsUser);

// send null params, expect 400
$result = $this->xdmodhelper->get($this->endpoint . 'dbstats', null);
$result = self::$xdmodhelper->get(self::ENDPOINT . 'dbstats', null);
$this->assertEquals(400, $result[1]['http_code']);

$this->assertArrayHasKey('success', $result[0]);
Expand All @@ -101,17 +105,17 @@ private function invalidParamsSupremmDbstatsEntries()
private function invalidResParamsNotFoundSupremmDbstatsEntries()
{
// validate properly
$this->xdmodhelper->authenticate($this->validateAsUser);
self::$xdmodhelper->authenticate(self::$validateAsUser);

// hardcode and send bogus resource_id param
$params = array(
'resource_id' => 99999,
'db_id' => 'summarydb'
);
$result = $this->xdmodhelper->get($this->endpoint . 'dbstats', $params);
$result = self::$xdmodhelper->get(self::ENDPOINT . 'dbstats', $params);

// Message will contain "no result found"
$this->assertContains("no result found for the given database", $result[0]['message']);
$this->assertStringContainsString("no result found for the given database", $result[0]['message']);

// result has success='false'
$this->assertArrayHasKey('success', $result[0]);
Expand All @@ -124,17 +128,17 @@ private function invalidResParamsNotFoundSupremmDbstatsEntries()
private function invalidParamsNotFoundSupremmDbstatsEntries()
{
// validate properly
$this->xdmodhelper->authenticate($this->validateAsUser);
self::$xdmodhelper->authenticate(self::$validateAsUser);

// hardcode and send bogus db_id param
$params = array(
'resource_id' => $this->fetchResourceId(),
'db_id' => 'db_does_not_exist'
);
$result = $this->xdmodhelper->get($this->endpoint . 'dbstats', $params);
$result = self::$xdmodhelper->get(self::ENDPOINT . 'dbstats', $params);

// Message will contain "no result found"
$this->assertContains("no result found for the given database", $result[0]['message']);
$this->assertStringContainsString("no result found for the given database", $result[0]['message']);

// result has success='false'
$this->assertArrayHasKey('success', $result[0]);
Expand All @@ -156,8 +160,8 @@ private function invalidSupremmUserDbstatsEntries($db, $userRole)
);

// reauthenticate as some (invalid) user role, not a 'mgr' role
$this->xdmodhelper->authenticate($userRole);
$result = $this->xdmodhelper->get($this->endpoint . 'dbstats', $params);
self::$xdmodhelper->authenticate($userRole);
$result = self::$xdmodhelper->get(self::ENDPOINT . 'dbstats', $params);

// result has success='false'
$this->assertArrayHasKey('success', $result[0]);
Expand All @@ -169,13 +173,13 @@ private function invalidSupremmUserDbstatsEntries($db, $userRole)

private function validateSupremmDbstatsEntries($db)
{
$this->xdmodhelper->authenticate($this->validateAsUser);
self::$xdmodhelper->authenticate(self::$validateAsUser);

$params = array(
'resource_id' => $this->fetchResourceId(),
'db_id' => $db
);
$result = $this->xdmodhelper->get($this->endpoint . 'dbstats', $params);
$result = self::$xdmodhelper->get(self::ENDPOINT . 'dbstats', $params);
$this->assertEquals(200, $result[1]['http_code']);

// result has success='true'
Expand All @@ -193,14 +197,15 @@ public function testInvalidUserCDSupremmResourceEntries()
{
// with wrong user authenticated: expect to receive a 403
$user = 'cd';
$this->xdmodhelper->authenticate($user);
self::$xdmodhelper->authenticate($user);

$result = $this->invalidSupremmResourceEntries(null);
$this->assertEquals(403, $result[1]['http_code']);
}

public function testInvalidUserSupremmResourceEntries()
{
self::$xdmodhelper->logoutDashboard();
// with no user authenticated: expect to receive a 401
$result = $this->invalidSupremmResourceEntries(null);
$this->assertEquals(401, $result[1]['http_code']);
Expand Down Expand Up @@ -258,7 +263,7 @@ public function testFetchDbstatsSummary($db = 'summarydb') {
// fetch accountdb stats
public function testFetchDbstatsAccount($db = 'accountdb') {

$this->markTestIncomplete('This enpoint only works on the XSEDE version of XDMoD.');
$this->markTestIncomplete('This endpoint only works on the XSEDE version of XDMoD.');

$item = $this->validateSupremmDbstatsEntries($db);

Expand Down Expand Up @@ -293,19 +298,19 @@ public function testFetchDbstatsAggregates($db = 'aggregates') {

public function testResourceEnableDisable() {

$this->xdmodhelper->authenticate($this->validateAsUser);
self::$xdmodhelper->authenticate(self::$validateAsUser);

$result = $this->xdmodhelper->get($this->endpoint . 'resources', null);
$result = self::$xdmodhelper->get(self::ENDPOINT . 'resources', null);
$this->assertEquals(5, sizeof($result[0]['data']));

shell_exec('mv /etc/xdmod/supremm_resources.json /etc/xdmod/supremm_resources.json.bak && jq \'.resources |= map(if .resource == "frearson" then .enabled |= false else . end)\' /etc/xdmod/supremm_resources.json.bak > /etc/xdmod/supremm_resources.json');

$result = $this->xdmodhelper->get($this->endpoint . 'resources', null);
$result = self::$xdmodhelper->get(self::ENDPOINT . 'resources', null);
$this->assertEquals(4, sizeof($result[0]['data']));

shell_exec('mv /etc/xdmod/supremm_resources.json.bak /etc/xdmod/supremm_resources.json');

$result = $this->xdmodhelper->get($this->endpoint . 'resources', null);
$result = self::$xdmodhelper->get(self::ENDPOINT . 'resources', null);
$this->assertEquals(5, sizeof($result[0]['data']));
}
}