Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Commit

Permalink
Replace requireRunToken feature with runTokenHash configuration
Browse files Browse the repository at this point in the history
The `run_token_hash.cache` file is no longer used.

Closes #327.
  • Loading branch information
supertassu authored Mar 9, 2023
1 parent 1892f91 commit a7e7d6a
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 60 deletions.
2 changes: 1 addition & 1 deletion config/defaultSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"saveReqTimeout": 10,
"saveRetryMax": 3,
"saveRetrySleep": 5,
"requireRunToken": false,
"runTokenHash": false,
"refreshControl": 0
},
"storage": {
Expand Down
9 changes: 2 additions & 7 deletions inc/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,10 @@ public static function getNameValidationRegex() {

public static function validateRunToken( TestSwarmContext $context, $runToken ) {
$conf = $context->getConf();
if ( !$conf->client->requireRunToken ) {
if ( !$conf->client->runTokenHash ) {
return true;
}
$cacheFile = $conf->storage->cacheDir . '/run_token_hash.cache';
if ( !is_readable( $cacheFile ) ) {
throw new SwarmException( 'Configuration requires a runToken but none has been configured.' );
}
$runTokenHash = trim( file_get_contents( $cacheFile ) );
if ( $runToken !== null && $runTokenHash === sha1( $runToken ) ) {
if ( $runToken !== null && $conf->client->runTokenHash === sha1( $runToken ) ) {
return true;
}
throw new SwarmException( 'This TestSwarm requires a run token. Either none was entered or it is invalid.' );
Expand Down
2 changes: 1 addition & 1 deletion inc/actions/GetrunAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function doAction() {
}

$runToken = $request->getVal( "run_token" );
if ( $conf->client->requireRunToken && !$runToken ) {
if ( $conf->client->runTokenHash && !$runToken ) {
$this->setError( "missing-parameters", "This TestSwarm does not allow unauthorized clients to join the swarm." );
return;
}
Expand Down
2 changes: 1 addition & 1 deletion inc/actions/PingAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function doAction() {
}

$runToken = $request->getVal( 'run_token' );
if ( $conf->client->requireRunToken && !$runToken ) {
if ( $conf->client->runTokenHash && !$runToken ) {
$this->setError( 'missing-parameters', 'This TestSwarm does not allow unauthorized clients to join the swarm.' );
return;
}
Expand Down
2 changes: 1 addition & 1 deletion inc/actions/SaverunAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function doAction() {
}

$runToken = $request->getVal( 'run_token' );
if ( $conf->client->requireRunToken && !$runToken ) {
if ( $conf->client->runTokenHash && !$runToken ) {
$this->setError( 'missing-parameters', 'This TestSwarm does not allow unauthorized clients to join the swarm.' );
return;
}
Expand Down
2 changes: 1 addition & 1 deletion inc/pages/HomePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected function initContent() {
. '</div>';

$html .= '<div class="span5"><div class="well">';
if ( !$conf->client->requireRunToken ) {
if ( !$conf->client->runTokenHash ) {
if ( $browserInfo->isInSwarmUaIndex() ) {
$auth = $context->getAuth();
$suggestedClientName = $auth ? $auth->project->id : '';
Expand Down
2 changes: 1 addition & 1 deletion inc/pages/RunPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ protected function initContent() {

$runToken = null;

if ( $conf->client->requireRunToken ) {
if ( $conf->client->runTokenHash ) {
$runToken = $request->getVal( "run_token" );
if ( !$runToken ) {
return '<div class="alert alert-error">This swarm has restricted access to join the swarm.</div>';
Expand Down
29 changes: 29 additions & 0 deletions scripts/generateRunToken.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
/**
* Refresh run token.
*
* @author Timo Tijhof
* @since 1.0.0
* @package TestSwarm
*/
define( 'SWARM_ENTRY', 'SCRIPT' );
require_once __DIR__ . '/../inc/init.php';

class GenerateRunTokenScript extends MaintenanceScript {

protected function init() {
$this->setDescription(
'Generates a new run token for clients and its hash for the configuration file.'
);
}

protected function execute() {
$runToken = sha1( mt_rand() );
$runTokenHash = sha1( $runToken );
$this->out( "New run token: $runToken" );
$this->out( "New token hash: $runTokenHash" );
}
}

$script = GenerateRunTokenScript::newFromContext( $swarmContext );
$script->run();
47 changes: 0 additions & 47 deletions scripts/refreshRunToken.php

This file was deleted.

0 comments on commit a7e7d6a

Please sign in to comment.