mirror of
https://code.mensbeam.com/MensBeam/Arsse.git
synced 2024-12-22 13:12:41 +00:00
Test feed fetching errors for Miniflux
This commit is contained in:
parent
727864f401
commit
36cc4928b9
4 changed files with 29 additions and 11 deletions
|
@ -15,7 +15,7 @@ class Exception extends \JKingWeb\Arsse\AbstractException {
|
||||||
protected const CURL_ERROR_MAP = [1 => "invalidUrl",3 => "invalidUrl",5 => "transmissionError","connectionFailed","connectionFailed","transmissionError","forbidden","unauthorized","transmissionError","transmissionError","transmissionError","transmissionError","connectionFailed","connectionFailed","transmissionError","transmissionError","transmissionError","transmissionError","transmissionError","invalidUrl","transmissionError","transmissionError","transmissionError","transmissionError",28 => "timeout","transmissionError","transmissionError","transmissionError","transmissionError","transmissionError",35 => "invalidCertificate","transmissionError","transmissionError","transmissionError","transmissionError",45 => "transmissionError","unauthorized","maxRedirect",52 => "transmissionError","invalidCertificate","invalidCertificate","transmissionError","transmissionError",58 => "invalidCertificate","invalidCertificate","invalidCertificate","transmissionError","invalidUrl","transmissionError","invalidCertificate","transmissionError","invalidCertificate","forbidden","invalidUrl","forbidden","transmissionError",73 => "transmissionError","transmissionError",77 => "invalidCertificate","invalidUrl",90 => "invalidCertificate","invalidCertificate","transmissionError",94 => "unauthorized","transmissionError","connectionFailed"];
|
protected const CURL_ERROR_MAP = [1 => "invalidUrl",3 => "invalidUrl",5 => "transmissionError","connectionFailed","connectionFailed","transmissionError","forbidden","unauthorized","transmissionError","transmissionError","transmissionError","transmissionError","connectionFailed","connectionFailed","transmissionError","transmissionError","transmissionError","transmissionError","transmissionError","invalidUrl","transmissionError","transmissionError","transmissionError","transmissionError",28 => "timeout","transmissionError","transmissionError","transmissionError","transmissionError","transmissionError",35 => "invalidCertificate","transmissionError","transmissionError","transmissionError","transmissionError",45 => "transmissionError","unauthorized","maxRedirect",52 => "transmissionError","invalidCertificate","invalidCertificate","transmissionError","transmissionError",58 => "invalidCertificate","invalidCertificate","invalidCertificate","transmissionError","invalidUrl","transmissionError","invalidCertificate","transmissionError","invalidCertificate","forbidden","invalidUrl","forbidden","transmissionError",73 => "transmissionError","transmissionError",77 => "invalidCertificate","invalidUrl",90 => "invalidCertificate","invalidCertificate","transmissionError",94 => "unauthorized","transmissionError","connectionFailed"];
|
||||||
protected const HTTP_ERROR_MAP = [401 => "unauthorized",403 => "forbidden",404 => "invalidUrl",408 => "timeout",410 => "invalidUrl",414 => "invalidUrl",451 => "invalidUrl"];
|
protected const HTTP_ERROR_MAP = [401 => "unauthorized",403 => "forbidden",404 => "invalidUrl",408 => "timeout",410 => "invalidUrl",414 => "invalidUrl",451 => "invalidUrl"];
|
||||||
|
|
||||||
public function __construct(string $msgID = "", $vars, \Throwable $e) {
|
public function __construct(string $msgID = "", $vars = null, \Throwable $e = null) {
|
||||||
if ($msgID === "") {
|
if ($msgID === "") {
|
||||||
assert($e !== null, new \Exception("Expecting Picofeed or Guzzle exception when no message specified."));
|
assert($e !== null, new \Exception("Expecting Picofeed or Guzzle exception when no message specified."));
|
||||||
if ($e instanceof BadResponseException) {
|
if ($e instanceof BadResponseException) {
|
||||||
|
|
|
@ -401,6 +401,7 @@ class V1 extends \JKingWeb\Arsse\REST\AbstractHandler {
|
||||||
10502 => "Fetch404",
|
10502 => "Fetch404",
|
||||||
10506 => "Fetch403",
|
10506 => "Fetch403",
|
||||||
10507 => "Fetch401",
|
10507 => "Fetch401",
|
||||||
|
10521 => "Fetch404",
|
||||||
][$e->getCode()] ?? "FetchOther";
|
][$e->getCode()] ?? "FetchOther";
|
||||||
return new ErrorResponse($msg, 502);
|
return new ErrorResponse($msg, 502);
|
||||||
}
|
}
|
||||||
|
@ -719,6 +720,8 @@ class V1 extends \JKingWeb\Arsse\REST\AbstractHandler {
|
||||||
10502 => "Fetch404",
|
10502 => "Fetch404",
|
||||||
10506 => "Fetch403",
|
10506 => "Fetch403",
|
||||||
10507 => "Fetch401",
|
10507 => "Fetch401",
|
||||||
|
10521 => "Fetch404",
|
||||||
|
10522 => "FetchFormat",
|
||||||
][$e->getCode()] ?? "FetchOther";
|
][$e->getCode()] ?? "FetchOther";
|
||||||
return new ErrorResponse($msg, 502);
|
return new ErrorResponse($msg, 502);
|
||||||
} catch (ExceptionInput $e) {
|
} catch (ExceptionInput $e) {
|
||||||
|
|
|
@ -19,6 +19,7 @@ return [
|
||||||
'API.Miniflux.Error.Fetch401' => 'You are not authorized to access this resource (invalid username/password)',
|
'API.Miniflux.Error.Fetch401' => 'You are not authorized to access this resource (invalid username/password)',
|
||||||
'API.Miniflux.Error.Fetch403' => 'Unable to fetch this resource (Status Code = 403)',
|
'API.Miniflux.Error.Fetch403' => 'Unable to fetch this resource (Status Code = 403)',
|
||||||
'API.Miniflux.Error.FetchOther' => 'Unable to fetch this resource',
|
'API.Miniflux.Error.FetchOther' => 'Unable to fetch this resource',
|
||||||
|
'API.Miniflux.Error.FetchFormat' => 'Unsupported feed format',
|
||||||
'API.Miniflux.Error.DuplicateCategory' => 'This category already exists.',
|
'API.Miniflux.Error.DuplicateCategory' => 'This category already exists.',
|
||||||
'API.Miniflux.Error.InvalidCategory' => 'Invalid category title "{title}"',
|
'API.Miniflux.Error.InvalidCategory' => 'Invalid category title "{title}"',
|
||||||
'API.Miniflux.Error.MissingCategory' => 'This category does not exist or does not belong to this user.',
|
'API.Miniflux.Error.MissingCategory' => 'This category does not exist or does not belong to this user.',
|
||||||
|
|
|
@ -15,7 +15,7 @@ use JKingWeb\Arsse\Db\ExceptionInput;
|
||||||
use JKingWeb\Arsse\Misc\Date;
|
use JKingWeb\Arsse\Misc\Date;
|
||||||
use JKingWeb\Arsse\REST\Miniflux\V1;
|
use JKingWeb\Arsse\REST\Miniflux\V1;
|
||||||
use JKingWeb\Arsse\REST\Miniflux\ErrorResponse;
|
use JKingWeb\Arsse\REST\Miniflux\ErrorResponse;
|
||||||
use JKingWeb\Arsse\Test\FeedException;
|
use JKingWeb\Arsse\Feed\Exception as FeedException;
|
||||||
use JKingWeb\Arsse\User\ExceptionConflict;
|
use JKingWeb\Arsse\User\ExceptionConflict;
|
||||||
use JKingWeb\Arsse\User\ExceptionInput as UserExceptionInput;
|
use JKingWeb\Arsse\User\ExceptionInput as UserExceptionInput;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
@ -602,12 +602,12 @@ class TestV1 extends \JKingWeb\Arsse\Test\AbstractTest {
|
||||||
$in2 = $out2 !== null;
|
$in2 = $out2 !== null;
|
||||||
$in3 = $out3 !== null;
|
$in3 = $out3 !== null;
|
||||||
if ($in1) {
|
if ($in1) {
|
||||||
\Phake::verify(Arsse::$db)->feedAdd($in['feed_url'], $in['username'] ?? "", $in['password'] ?? "", true, $in['crawler'] ?? false);
|
\Phake::verify(Arsse::$db)->feedAdd($in['feed_url'], $in['username'] ?? "", $in['password'] ?? "", false, $in['crawler'] ?? false);
|
||||||
} else {
|
} else {
|
||||||
\Phake::verify(Arsse::$db, \Phake::times(0))->feedAdd;
|
\Phake::verify(Arsse::$db, \Phake::times(0))->feedAdd;
|
||||||
}
|
}
|
||||||
if ($in2) {
|
if ($in2) {
|
||||||
\Phake::verify(Arsse::$db)->subscriptionAdd("john.doe@example.com", $in['feed_url'], $in['username'] ?? "", $in['password'] ?? "", true, $in['crawler'] ?? false);
|
\Phake::verify(Arsse::$db)->subscriptionAdd("john.doe@example.com", $in['feed_url'], $in['username'] ?? "", $in['password'] ?? "", false, $in['crawler'] ?? false);
|
||||||
} else {
|
} else {
|
||||||
\Phake::verify(Arsse::$db, \Phake::times(0))->subscriptionAdd;
|
\Phake::verify(Arsse::$db, \Phake::times(0))->subscriptionAdd;
|
||||||
}
|
}
|
||||||
|
@ -627,13 +627,27 @@ class TestV1 extends \JKingWeb\Arsse\Test\AbstractTest {
|
||||||
public function provideFeedCreations(): iterable {
|
public function provideFeedCreations(): iterable {
|
||||||
self::clearData();
|
self::clearData();
|
||||||
return [
|
return [
|
||||||
[['category_id' => 1], null, null, null, new ErrorResponse(["MissingInputValue", 'field' => "feed_url"], 422)],
|
[['category_id' => 1], null, null, null, new ErrorResponse(["MissingInputValue", 'field' => "feed_url"], 422)],
|
||||||
[['feed_url' => "http://example.com/"], null, null, null, new ErrorResponse(["MissingInputValue", 'field' => "category_id"], 422)],
|
[['feed_url' => "http://example.com/"], null, null, null, new ErrorResponse(["MissingInputValue", 'field' => "category_id"], 422)],
|
||||||
[['feed_url' => "http://example.com/", 'category_id' => "1"], null, null, null, new ErrorResponse(["InvalidInputType", 'field' => "category_id", 'expected' => "integer", 'actual' => "string"], 422)],
|
[['feed_url' => "http://example.com/", 'category_id' => "1"], null, null, null, new ErrorResponse(["InvalidInputType", 'field' => "category_id", 'expected' => "integer", 'actual' => "string"], 422)],
|
||||||
[['feed_url' => "Not a URL", 'category_id' => 1], null, null, null, new ErrorResponse(["InvalidInputValue", 'field' => "feed_url"], 422)],
|
[['feed_url' => "Not a URL", 'category_id' => 1], null, null, null, new ErrorResponse(["InvalidInputValue", 'field' => "feed_url"], 422)],
|
||||||
[['feed_url' => "http://example.com/", 'category_id' => 0], null, null, null, new ErrorResponse(["InvalidInputValue", 'field' => "category_id"], 422)],
|
[['feed_url' => "http://example.com/", 'category_id' => 0], null, null, null, new ErrorResponse(["InvalidInputValue", 'field' => "category_id"], 422)],
|
||||||
[['feed_url' => "http://example.com/", 'category_id' => 1, 'keeplist_rules' => "["], null, null, null, new ErrorResponse(["InvalidInputValue", 'field' => "keeplist_rules"], 422)],
|
[['feed_url' => "http://example.com/", 'category_id' => 1, 'keeplist_rules' => "["], null, null, null, new ErrorResponse(["InvalidInputValue", 'field' => "keeplist_rules"], 422)],
|
||||||
[['feed_url' => "http://example.com/", 'category_id' => 1, 'blocklist_rules' => "["], null, null, null, new ErrorResponse(["InvalidInputValue", 'field' => "blocklist_rules"], 422)],
|
[['feed_url' => "http://example.com/", 'category_id' => 1, 'blocklist_rules' => "["], null, null, null, new ErrorResponse(["InvalidInputValue", 'field' => "blocklist_rules"], 422)],
|
||||||
|
[['feed_url' => "http://example.com/", 'category_id' => 1], new FeedException("internalError"), null, null, new ErrorResponse("FetchOther", 502)],
|
||||||
|
[['feed_url' => "http://example.com/", 'category_id' => 1], new FeedException("invalidCertificate"), null, null, new ErrorResponse("FetchOther", 502)],
|
||||||
|
[['feed_url' => "http://example.com/", 'category_id' => 1], new FeedException("invalidUrl"), null, null, new ErrorResponse("Fetch404", 502)],
|
||||||
|
[['feed_url' => "http://example.com/", 'category_id' => 1], new FeedException("maxRedirect"), null, null, new ErrorResponse("FetchOther", 502)],
|
||||||
|
[['feed_url' => "http://example.com/", 'category_id' => 1], new FeedException("maxSize"), null, null, new ErrorResponse("FetchOther", 502)],
|
||||||
|
[['feed_url' => "http://example.com/", 'category_id' => 1], new FeedException("timeout"), null, null, new ErrorResponse("FetchOther", 502)],
|
||||||
|
[['feed_url' => "http://example.com/", 'category_id' => 1], new FeedException("forbidden"), null, null, new ErrorResponse("Fetch403", 502)],
|
||||||
|
[['feed_url' => "http://example.com/", 'category_id' => 1], new FeedException("unauthorized"), null, null, new ErrorResponse("Fetch401", 502)],
|
||||||
|
[['feed_url' => "http://example.com/", 'category_id' => 1], new FeedException("transmissionError"), null, null, new ErrorResponse("FetchOther", 502)],
|
||||||
|
[['feed_url' => "http://example.com/", 'category_id' => 1], new FeedException("connectionFailed"), null, null, new ErrorResponse("FetchOther", 502)],
|
||||||
|
[['feed_url' => "http://example.com/", 'category_id' => 1], new FeedException("malformedXml"), null, null, new ErrorResponse("FetchOther", 502)],
|
||||||
|
[['feed_url' => "http://example.com/", 'category_id' => 1], new FeedException("xmlEntity"), null, null, new ErrorResponse("FetchOther", 502)],
|
||||||
|
[['feed_url' => "http://example.com/", 'category_id' => 1], new FeedException("subscriptionNotFound"), null, null, new ErrorResponse("Fetch404", 502)],
|
||||||
|
[['feed_url' => "http://example.com/", 'category_id' => 1], new FeedException("unsupportedFeedFormat"), null, null, new ErrorResponse("FetchFormat", 502)],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue