mirror of
https://github.com/smogon/pokemon-showdown-loginserver.git
synced 2026-09-12 20:25:12 -05:00
Add test for servers loading
This commit is contained in:
@@ -162,7 +162,7 @@ export class Dispatcher {
|
||||
}
|
||||
return list;
|
||||
}
|
||||
static servers: {[k: string]: RegisteredServer} = (() => {
|
||||
static loadServers(): {[k: string]: RegisteredServer} {
|
||||
try {
|
||||
const stdout = child.execFileSync(
|
||||
`php`, ['-f', 'src/lib/load-servers.php', Config.serverlist]
|
||||
@@ -172,6 +172,7 @@ export class Dispatcher {
|
||||
if (e.code !== 'ENOENT') throw e;
|
||||
}
|
||||
return {};
|
||||
})();
|
||||
}
|
||||
static servers: {[k: string]: RegisteredServer} = Dispatcher.loadServers();
|
||||
static ActionError = ActionError;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
*/
|
||||
import {strict as assert} from 'assert';
|
||||
import {Config} from '../config-loader';
|
||||
import {Dispatcher} from '../dispatcher';
|
||||
import * as path from 'path';
|
||||
|
||||
import * as utils from './test-utils';
|
||||
|
||||
@@ -65,4 +67,18 @@ describe('Dispatcher features', () => {
|
||||
assert(act === 'mmr');
|
||||
assert(body?.userid === 'mia');
|
||||
});
|
||||
it("Should load servers properly", () => {
|
||||
Config.serverlist = path.join(__dirname, '/../../', 'src/test/fixtures/servers.php');
|
||||
const servers = Dispatcher.loadServers();
|
||||
const expected = {
|
||||
showdown: {
|
||||
name: 'Smogon University',
|
||||
id: 'showdown',
|
||||
server: 'sim.psim.us',
|
||||
port: 8000,
|
||||
owner: 'mia'
|
||||
},
|
||||
};
|
||||
assert.deepStrictEqual(expected, servers);
|
||||
});
|
||||
});
|
||||
|
||||
18
src/test/fixtures/servers.php
vendored
Normal file
18
src/test/fixtures/servers.php
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
/* if ((substr($_SERVER['REMOTE_ADDR'],0,11) === '69.164.163.') ||
|
||||
(@substr($_SERVER['HTTP_X_FORWARDED_FOR'],0,11) === '69.164.163.')) {
|
||||
file_put_contents(dirname(__FILE__).'/log', "blocked: ".var_export($_SERVER, TRUE)."\n\n", FILE_APPEND);
|
||||
die('website disabled');
|
||||
} */
|
||||
|
||||
$PokemonServers = array (
|
||||
'showdown' =>
|
||||
array (
|
||||
'name' => 'Smogon University',
|
||||
'id' => 'showdown',
|
||||
'server' => 'sim.psim.us',
|
||||
'port' => 8000,
|
||||
'owner' => 'mia',
|
||||
),
|
||||
);
|
||||
@@ -95,4 +95,4 @@ export async function randomBytes(size = 128) {
|
||||
|
||||
before(async () => {
|
||||
await setupDB();
|
||||
});
|
||||
});
|
||||
@@ -12,6 +12,6 @@
|
||||
},
|
||||
"types": ["node"],
|
||||
"include": [
|
||||
"./src/*",
|
||||
"./src/*", "./src/test/*",
|
||||
],
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user