1
0
Fork 0
mirror of synced 2024-06-28 11:10:46 +12:00

Fixed tests

This commit is contained in:
Eldad Fux 2020-07-01 00:38:06 +03:00
parent b34a71e1bf
commit fd90a57ece
3 changed files with 123 additions and 141 deletions

View file

@ -660,7 +660,7 @@ App::get('/v1/account/logs')
->label('sdk.namespace', 'account') ->label('sdk.namespace', 'account')
->label('sdk.method', 'getLogs') ->label('sdk.method', 'getLogs')
->label('sdk.description', '/docs/references/account/get-logs.md') ->label('sdk.description', '/docs/references/account/get-logs.md')
->action(function ($response, $register, $project, $user) { ->action(function ($response, $register, $project, $user, $locale) {
/** @var Utopia\Response $response */ /** @var Utopia\Response $response */
/** @var Appwrite\Database\Document $project */ /** @var Appwrite\Database\Document $project */
/** @var Appwrite\Database\Document $user */ /** @var Appwrite\Database\Document $user */
@ -726,7 +726,7 @@ App::get('/v1/account/logs')
} }
$response->json($output); $response->json($output);
}, ['response', 'register', 'project', 'user']); }, ['response', 'register', 'project', 'user', 'locale']);
App::patch('/v1/account/name') App::patch('/v1/account/name')
->desc('Update Account Name') ->desc('Update Account Name')

View file

@ -577,7 +577,7 @@ App::delete('/v1/storage/files/:fileId')
; ;
$response->noContent(); $response->noContent();
}, ['fileId', 'response', 'projectDB', 'webhook', 'audit', 'usage']); }, ['response', 'projectDB', 'webhook', 'audit', 'usage']);
// App::get('/v1/storage/files/:fileId/scan') // App::get('/v1/storage/files/:fileId/scan')
// ->desc('Scan Storage') // ->desc('Scan Storage')

View file

@ -19,10 +19,8 @@ App::get('/v1/mock/tests/foo')
->param('x', '', function () { return new Text(100); }, 'Sample string param') ->param('x', '', function () { return new Text(100); }, 'Sample string param')
->param('y', '', function () { return new Numeric(); }, 'Sample numeric param') ->param('y', '', function () { return new Numeric(); }, 'Sample numeric param')
->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param') ->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param')
->action( ->action(function ($x, $y, $z) {
function ($x, $y, $z) { });
}
);
App::post('/v1/mock/tests/foo') App::post('/v1/mock/tests/foo')
->desc('Mock a post request for SDK tests') ->desc('Mock a post request for SDK tests')
@ -33,10 +31,8 @@ App::post('/v1/mock/tests/foo')
->param('x', '', function () { return new Text(100); }, 'Sample string param') ->param('x', '', function () { return new Text(100); }, 'Sample string param')
->param('y', '', function () { return new Numeric(); }, 'Sample numeric param') ->param('y', '', function () { return new Numeric(); }, 'Sample numeric param')
->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param') ->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param')
->action( ->action(function ($x, $y, $z) {
function ($x, $y, $z) { });
}
);
App::patch('/v1/mock/tests/foo') App::patch('/v1/mock/tests/foo')
->desc('Mock a patch request for SDK tests') ->desc('Mock a patch request for SDK tests')
@ -47,10 +43,8 @@ App::patch('/v1/mock/tests/foo')
->param('x', '', function () { return new Text(100); }, 'Sample string param') ->param('x', '', function () { return new Text(100); }, 'Sample string param')
->param('y', '', function () { return new Numeric(); }, 'Sample numeric param') ->param('y', '', function () { return new Numeric(); }, 'Sample numeric param')
->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param') ->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param')
->action( ->action(function ($x, $y, $z) {
function ($x, $y, $z) { });
}
);
App::put('/v1/mock/tests/foo') App::put('/v1/mock/tests/foo')
->desc('Mock a put request for SDK tests') ->desc('Mock a put request for SDK tests')
@ -61,10 +55,8 @@ App::put('/v1/mock/tests/foo')
->param('x', '', function () { return new Text(100); }, 'Sample string param') ->param('x', '', function () { return new Text(100); }, 'Sample string param')
->param('y', '', function () { return new Numeric(); }, 'Sample numeric param') ->param('y', '', function () { return new Numeric(); }, 'Sample numeric param')
->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param') ->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param')
->action( ->action(function ($x, $y, $z) {
function ($x, $y, $z) { });
}
);
App::delete('/v1/mock/tests/foo') App::delete('/v1/mock/tests/foo')
->desc('Mock a delete request for SDK tests') ->desc('Mock a delete request for SDK tests')
@ -75,10 +67,8 @@ App::delete('/v1/mock/tests/foo')
->param('x', '', function () { return new Text(100); }, 'Sample string param') ->param('x', '', function () { return new Text(100); }, 'Sample string param')
->param('y', '', function () { return new Numeric(); }, 'Sample numeric param') ->param('y', '', function () { return new Numeric(); }, 'Sample numeric param')
->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param') ->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param')
->action( ->action(function ($x, $y, $z) {
function ($x, $y, $z) { });
}
);
App::get('/v1/mock/tests/bar') App::get('/v1/mock/tests/bar')
->desc('Mock a get request for SDK tests') ->desc('Mock a get request for SDK tests')
@ -89,10 +79,8 @@ App::get('/v1/mock/tests/bar')
->param('x', '', function () { return new Text(100); }, 'Sample string param') ->param('x', '', function () { return new Text(100); }, 'Sample string param')
->param('y', '', function () { return new Numeric(); }, 'Sample numeric param') ->param('y', '', function () { return new Numeric(); }, 'Sample numeric param')
->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param') ->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param')
->action( ->action(function ($x, $y, $z) {
function ($x, $y, $z) { });
}
);
App::post('/v1/mock/tests/bar') App::post('/v1/mock/tests/bar')
->desc('Mock a post request for SDK tests') ->desc('Mock a post request for SDK tests')
@ -103,10 +91,8 @@ App::post('/v1/mock/tests/bar')
->param('x', '', function () { return new Text(100); }, 'Sample string param') ->param('x', '', function () { return new Text(100); }, 'Sample string param')
->param('y', '', function () { return new Numeric(); }, 'Sample numeric param') ->param('y', '', function () { return new Numeric(); }, 'Sample numeric param')
->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param') ->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param')
->action( ->action(function ($x, $y, $z) {
function ($x, $y, $z) { });
}
);
App::patch('/v1/mock/tests/bar') App::patch('/v1/mock/tests/bar')
->desc('Mock a patch request for SDK tests') ->desc('Mock a patch request for SDK tests')
@ -117,10 +103,8 @@ App::patch('/v1/mock/tests/bar')
->param('x', '', function () { return new Text(100); }, 'Sample string param') ->param('x', '', function () { return new Text(100); }, 'Sample string param')
->param('y', '', function () { return new Numeric(); }, 'Sample numeric param') ->param('y', '', function () { return new Numeric(); }, 'Sample numeric param')
->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param') ->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param')
->action( ->action(function ($x, $y, $z) {
function ($x, $y, $z) { });
}
);
App::put('/v1/mock/tests/bar') App::put('/v1/mock/tests/bar')
->desc('Mock a put request for SDK tests') ->desc('Mock a put request for SDK tests')
@ -131,10 +115,8 @@ App::put('/v1/mock/tests/bar')
->param('x', '', function () { return new Text(100); }, 'Sample string param') ->param('x', '', function () { return new Text(100); }, 'Sample string param')
->param('y', '', function () { return new Numeric(); }, 'Sample numeric param') ->param('y', '', function () { return new Numeric(); }, 'Sample numeric param')
->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param') ->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param')
->action( ->action(function ($x, $y, $z) {
function ($x, $y, $z) { });
}
);
App::delete('/v1/mock/tests/bar') App::delete('/v1/mock/tests/bar')
->desc('Mock a delete request for SDK tests') ->desc('Mock a delete request for SDK tests')
@ -145,10 +127,8 @@ App::delete('/v1/mock/tests/bar')
->param('x', '', function () { return new Text(100); }, 'Sample string param') ->param('x', '', function () { return new Text(100); }, 'Sample string param')
->param('y', '', function () { return new Numeric(); }, 'Sample numeric param') ->param('y', '', function () { return new Numeric(); }, 'Sample numeric param')
->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param') ->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param')
->action( ->action(function ($x, $y, $z) {
function ($x, $y, $z) { });
}
);
App::post('/v1/mock/tests/general/upload') App::post('/v1/mock/tests/general/upload')
->desc('Mock a post request for SDK tests') ->desc('Mock a post request for SDK tests')
@ -161,32 +141,32 @@ App::post('/v1/mock/tests/general/upload')
->param('y', '', function () { return new Numeric(); }, 'Sample numeric param') ->param('y', '', function () { return new Numeric(); }, 'Sample numeric param')
->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param') ->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param')
->param('file', [], function () { return new File(); }, 'Sample file param', false) ->param('file', [], function () { return new File(); }, 'Sample file param', false)
->action( ->action(function ($x, $y, $z, $file, $request) {
function ($x, $y, $z, $file) use ($request) { /** @var Utopia\Request $request */
$file = $request->getFiles('file');
$file['tmp_name'] = (\is_array($file['tmp_name'])) ? $file['tmp_name'] : [$file['tmp_name']]; $file = $request->getFiles('file');
$file['name'] = (\is_array($file['name'])) ? $file['name'] : [$file['name']]; $file['tmp_name'] = (\is_array($file['tmp_name'])) ? $file['tmp_name'] : [$file['tmp_name']];
$file['size'] = (\is_array($file['size'])) ? $file['size'] : [$file['size']]; $file['name'] = (\is_array($file['name'])) ? $file['name'] : [$file['name']];
$file['size'] = (\is_array($file['size'])) ? $file['size'] : [$file['size']];
foreach ($file['name'] as $i => $name) { foreach ($file['name'] as $i => $name) {
if ($name !== 'file.png') { if ($name !== 'file.png') {
throw new Exception('Wrong file name', 400); throw new Exception('Wrong file name', 400);
}
}
foreach ($file['size'] as $i => $size) {
if ($size !== 38756) {
throw new Exception('Wrong file size', 400);
}
}
foreach ($file['tmp_name'] as $i => $tmpName) {
if (\md5(\file_get_contents($tmpName)) !== 'd80e7e6999a3eb2ae0d631a96fe135a4') {
throw new Exception('Wrong file uploaded', 400);
}
} }
} }
);
foreach ($file['size'] as $i => $size) {
if ($size !== 38756) {
throw new Exception('Wrong file size', 400);
}
}
foreach ($file['tmp_name'] as $i => $tmpName) {
if (\md5(\file_get_contents($tmpName)) !== 'd80e7e6999a3eb2ae0d631a96fe135a4') {
throw new Exception('Wrong file uploaded', 400);
}
}
}, ['request']);
App::get('/v1/mock/tests/general/redirect') App::get('/v1/mock/tests/general/redirect')
->desc('Mock a post request for SDK tests') ->desc('Mock a post request for SDK tests')
@ -194,11 +174,11 @@ App::get('/v1/mock/tests/general/redirect')
->label('sdk.namespace', 'general') ->label('sdk.namespace', 'general')
->label('sdk.method', 'redirect') ->label('sdk.method', 'redirect')
->label('sdk.description', 'Mock a redirect request for SDK tests') ->label('sdk.description', 'Mock a redirect request for SDK tests')
->action( ->action(function ($response) {
function () use ($response) { /** @var Utopia\Response $response */
$response->redirect('/v1/mock/tests/general/redirected');
} $response->redirect('/v1/mock/tests/general/redirected');
); }, ['response']);
App::get('/v1/mock/tests/general/redirected') App::get('/v1/mock/tests/general/redirected')
->desc('Mock a post request for SDK tests') ->desc('Mock a post request for SDK tests')
@ -206,10 +186,8 @@ App::get('/v1/mock/tests/general/redirected')
->label('sdk.namespace', 'general') ->label('sdk.namespace', 'general')
->label('sdk.method', 'redirected') ->label('sdk.method', 'redirected')
->label('sdk.description', 'Mock a redirected request for SDK tests') ->label('sdk.description', 'Mock a redirected request for SDK tests')
->action( ->action(function () {
function () { });
}
);
App::get('/v1/mock/tests/general/set-cookie') App::get('/v1/mock/tests/general/set-cookie')
->desc('Mock a cookie request for SDK tests') ->desc('Mock a cookie request for SDK tests')
@ -217,11 +195,11 @@ App::get('/v1/mock/tests/general/set-cookie')
->label('sdk.namespace', 'general') ->label('sdk.namespace', 'general')
->label('sdk.method', 'setCookie') ->label('sdk.method', 'setCookie')
->label('sdk.description', 'Mock a set cookie request for SDK tests') ->label('sdk.description', 'Mock a set cookie request for SDK tests')
->action( ->action(function ($response) {
function () use ($response) { /** @var Utopia\Response $response */
$response->addCookie('cookieName', 'cookieValue', \time() + 31536000, '/', 'localhost', true, true);
} $response->addCookie('cookieName', 'cookieValue', \time() + 31536000, '/', 'localhost', true, true);
); }, ['response']);
App::get('/v1/mock/tests/general/get-cookie') App::get('/v1/mock/tests/general/get-cookie')
->desc('Mock a cookie request for SDK tests') ->desc('Mock a cookie request for SDK tests')
@ -229,13 +207,13 @@ App::get('/v1/mock/tests/general/get-cookie')
->label('sdk.namespace', 'general') ->label('sdk.namespace', 'general')
->label('sdk.method', 'getCookie') ->label('sdk.method', 'getCookie')
->label('sdk.description', 'Mock a get cookie request for SDK tests') ->label('sdk.description', 'Mock a get cookie request for SDK tests')
->action( ->action(function ($request) {
function () use ($request) { /** @var Utopia\Request $request */
if ($request->getCookie('cookieName', '') !== 'cookieValue') {
throw new Exception('Missing cookie value', 400); if ($request->getCookie('cookieName', '') !== 'cookieValue') {
} throw new Exception('Missing cookie value', 400);
} }
); }, ['request']);
App::get('/v1/mock/tests/general/empty') App::get('/v1/mock/tests/general/empty')
->desc('Mock a post request for SDK tests') ->desc('Mock a post request for SDK tests')
@ -243,12 +221,12 @@ App::get('/v1/mock/tests/general/empty')
->label('sdk.namespace', 'general') ->label('sdk.namespace', 'general')
->label('sdk.method', 'empty') ->label('sdk.method', 'empty')
->label('sdk.description', 'Mock a redirected request for SDK tests') ->label('sdk.description', 'Mock a redirected request for SDK tests')
->action( ->action(function ($response) {
function () use ($response) { /** @var Utopia\Response $response */
$response->noContent();
exit(); $response->noContent();
} exit();
); }, ['response']);
App::get('/v1/mock/tests/general/oauth2') App::get('/v1/mock/tests/general/oauth2')
->desc('Mock an OAuth2 login route') ->desc('Mock an OAuth2 login route')
@ -258,11 +236,11 @@ App::get('/v1/mock/tests/general/oauth2')
->param('redirect_uri', '', function () { return new Host(['localhost']); }, 'OAuth2 Redirect URI.') // Important to deny an open redirect attack ->param('redirect_uri', '', function () { return new Host(['localhost']); }, 'OAuth2 Redirect URI.') // Important to deny an open redirect attack
->param('scope', '', function () { return new Text(100); }, 'OAuth2 scope list.') ->param('scope', '', function () { return new Text(100); }, 'OAuth2 scope list.')
->param('state', '', function () { return new Text(1024); }, 'OAuth2 state.') ->param('state', '', function () { return new Text(1024); }, 'OAuth2 state.')
->action( ->action(function ($clientId, $redirectURI, $scope, $state, $response) {
function ($clientId, $redirectURI, $scope, $state) use ($response) { /** @var Utopia\Response $response */
$response->redirect($redirectURI.'?'.\http_build_query(['code' => 'abcdef', 'state' => $state]));
} $response->redirect($redirectURI.'?'.\http_build_query(['code' => 'abcdef', 'state' => $state]));
); }, ['response']);
App::get('/v1/mock/tests/general/oauth2/token') App::get('/v1/mock/tests/general/oauth2/token')
->desc('Mock an OAuth2 login route') ->desc('Mock an OAuth2 login route')
@ -272,68 +250,72 @@ App::get('/v1/mock/tests/general/oauth2/token')
->param('redirect_uri', '', function () { return new Host(['localhost']); }, 'OAuth2 Redirect URI.') ->param('redirect_uri', '', function () { return new Host(['localhost']); }, 'OAuth2 Redirect URI.')
->param('client_secret', '', function () { return new Text(100); }, 'OAuth2 scope list.') ->param('client_secret', '', function () { return new Text(100); }, 'OAuth2 scope list.')
->param('code', '', function () { return new Text(100); }, 'OAuth2 state.') ->param('code', '', function () { return new Text(100); }, 'OAuth2 state.')
->action( ->action(function ($clientId, $redirectURI, $clientSecret, $code, $response) {
function ($clientId, $redirectURI, $clientSecret, $code) use ($response) { /** @var Utopia\Response $response */
if ($clientId != '1') {
throw new Exception('Invalid client ID');
}
if ($clientSecret != '123456') { if ($clientId != '1') {
throw new Exception('Invalid client secret'); throw new Exception('Invalid client ID');
}
if ($code != 'abcdef') {
throw new Exception('Invalid token');
}
$response->json(['access_token' => '123456']);
} }
);
if ($clientSecret != '123456') {
throw new Exception('Invalid client secret');
}
if ($code != 'abcdef') {
throw new Exception('Invalid token');
}
$response->json(['access_token' => '123456']);
}, ['response']);
App::get('/v1/mock/tests/general/oauth2/user') App::get('/v1/mock/tests/general/oauth2/user')
->desc('Mock an OAuth2 user route') ->desc('Mock an OAuth2 user route')
->label('scope', 'public') ->label('scope', 'public')
->label('docs', false) ->label('docs', false)
->param('token', '', function () { return new Text(100); }, 'OAuth2 Access Token.') ->param('token', '', function () { return new Text(100); }, 'OAuth2 Access Token.')
->action( ->action(function ($token, $response) {
function ($token) use ($response) { /** @var Utopia\Response $response */
if ($token != '123456') {
throw new Exception('Invalid token');
}
$response->json([ if ($token != '123456') {
'id' => 1, throw new Exception('Invalid token');
'name' => 'User Name',
'email' => 'user@localhost.test',
]);
} }
);
$response->json([
'id' => 1,
'name' => 'User Name',
'email' => 'user@localhost.test',
]);
}, ['response']);
App::get('/v1/mock/tests/general/oauth2/success') App::get('/v1/mock/tests/general/oauth2/success')
->label('scope', 'public') ->label('scope', 'public')
->label('docs', false) ->label('docs', false)
->action( ->action(function ($response) {
function () use ($response) { /** @var Utopia\Response $response */
$response->json([
'result' => 'success', $response->json([
]); 'result' => 'success',
} ]);
); }, ['response']);
App::get('/v1/mock/tests/general/oauth2/failure') App::get('/v1/mock/tests/general/oauth2/failure')
->label('scope', 'public') ->label('scope', 'public')
->label('docs', false) ->label('docs', false)
->action( ->action(function ($response) {
function () use ($response) { /** @var Utopia\Response $response */
$response
->setStatusCode(Response::STATUS_CODE_BAD_REQUEST) $response
->json([ ->setStatusCode(Response::STATUS_CODE_BAD_REQUEST)
'result' => 'failure', ->json([
]); 'result' => 'failure',
} ]);
); }, ['response']);
App::shutdown(function($utopia, $response, $request) {
/** @var Utopia\App $utopia */
/** @var Utopia\Request $request */
/** @var Utopia\Response $response */
App::shutdown(function($response, $request, $utopia) {
$result = []; $result = [];
$route = $utopia->match($request); $route = $utopia->match($request);
$path = APP_STORAGE_CACHE.'/tests.json'; $path = APP_STORAGE_CACHE.'/tests.json';
@ -352,4 +334,4 @@ App::shutdown(function($response, $request, $utopia) {
} }
$response->json(['result' => $route->getMethod() . ':' . $route->getURL() . ':passed']); $response->json(['result' => $route->getMethod() . ':' . $route->getURL() . ':passed']);
}, ['response', 'request', 'utopia'], 'mock'); }, ['utopia', 'response', 'request'], 'mock');