mirror of https://gitee.com/bigwinds/arangodb
issue 430.2: ensure error conditions are thrown on view velocypack generation failure (#5988)
This commit is contained in:
parent
5b5ed838cb
commit
02a2a02a01
|
@ -53,8 +53,15 @@ void RestViewHandler::getView(std::string const& nameOrId, bool detailed) {
|
|||
arangodb::velocypack::Builder builder;
|
||||
|
||||
builder.openObject();
|
||||
view->toVelocyPack(builder, detailed, false);
|
||||
|
||||
auto res = view->toVelocyPack(builder, detailed, false);
|
||||
|
||||
builder.close();
|
||||
|
||||
if (!res.ok()) {
|
||||
generateError(res);
|
||||
}
|
||||
|
||||
generateOk(rest::ResponseCode::OK, builder);
|
||||
}
|
||||
|
||||
|
@ -306,8 +313,14 @@ void RestViewHandler::getViews() {
|
|||
for (auto view: views) {
|
||||
if (view && (!excludeSystem || !view->system())) {
|
||||
builder.openObject();
|
||||
view->toVelocyPack(builder, false, false);
|
||||
|
||||
auto res = view->toVelocyPack(builder, false, false);
|
||||
|
||||
builder.close();
|
||||
|
||||
if (!res.ok()) {
|
||||
generateError(res);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -463,9 +463,15 @@ static void JS_PropertiesViewVocbase(
|
|||
arangodb::velocypack::Builder builder;
|
||||
|
||||
builder.openObject();
|
||||
view->toVelocyPack(builder, true, false);
|
||||
|
||||
auto res = view->toVelocyPack(builder, true, false);
|
||||
|
||||
builder.close();
|
||||
|
||||
if (!res.ok()) {
|
||||
TRI_V8_THROW_EXCEPTION(res);
|
||||
}
|
||||
|
||||
// return the current parameter set
|
||||
TRI_V8_RETURN(TRI_VPackToV8(isolate, builder.slice()) ->ToObject());
|
||||
TRI_V8_TRY_CATCH_END
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
#include "Aql/SortCondition.h"
|
||||
#include "Basics/ArangoGlobalContext.h"
|
||||
#include "Basics/files.h"
|
||||
#include "Utils/ExecContext.h"
|
||||
|
||||
#if USE_ENTERPRISE
|
||||
#include "Enterprise/Ldap/LdapFeature.h"
|
||||
|
@ -339,6 +340,87 @@ SECTION("test_defaults") {
|
|||
CHECK((0 == cids.size()));
|
||||
CHECK((true == logicalCollection->getIndexes().empty()));
|
||||
}
|
||||
|
||||
// view definition with links
|
||||
{
|
||||
auto collectionJson = arangodb::velocypack::Parser::fromJson("{ \"name\": \"testCollection\", \"id\": 100 }");
|
||||
auto viewCreateJson = arangodb::velocypack::Parser::fromJson("{ \"name\": \"testView\", \"type\": \"arangosearch\" }");
|
||||
auto viewUpdateJson = arangodb::velocypack::Parser::fromJson("{ \"links\": { \"testCollection\": {} } }");
|
||||
|
||||
TRI_vocbase_t vocbase(TRI_vocbase_type_e::TRI_VOCBASE_TYPE_NORMAL, 1, "testVocbase");
|
||||
auto* logicalCollection = vocbase.createCollection(collectionJson->slice());
|
||||
REQUIRE((nullptr != logicalCollection));
|
||||
auto logicalView = vocbase.createView(viewCreateJson->slice());
|
||||
REQUIRE((false == !logicalView));
|
||||
|
||||
CHECK((true == logicalCollection->getIndexes().empty()));
|
||||
CHECK((true == logicalView->visitCollections([](TRI_voc_cid_t)->bool { return false; })));
|
||||
|
||||
CHECK((logicalView->updateProperties(viewUpdateJson->slice(), true, false).ok()));
|
||||
|
||||
CHECK((false == logicalCollection->getIndexes().empty()));
|
||||
CHECK((false == logicalView->visitCollections([](TRI_voc_cid_t)->bool { return false; })));
|
||||
|
||||
arangodb::iresearch::IResearchViewMeta expectedMeta;
|
||||
arangodb::velocypack::Builder builder;
|
||||
|
||||
builder.openObject();
|
||||
logicalView->toVelocyPack(builder, true, false);
|
||||
builder.close();
|
||||
|
||||
auto slice = builder.slice();
|
||||
arangodb::iresearch::IResearchViewMeta meta;
|
||||
std::string error;
|
||||
CHECK((slice.isObject()));
|
||||
CHECK((6U == slice.length()));
|
||||
CHECK(slice.get("name").copyString() == "testView");
|
||||
CHECK(slice.get("type").copyString() == arangodb::iresearch::DATA_SOURCE_TYPE.name());
|
||||
CHECK((false == slice.hasKey("deleted")));
|
||||
CHECK((meta.init(slice, error) && expectedMeta == meta));
|
||||
|
||||
auto tmpSlice = slice.get("links");
|
||||
CHECK((true == tmpSlice.isObject() && 1 == tmpSlice.length()));
|
||||
CHECK((true == tmpSlice.hasKey("testCollection")));
|
||||
}
|
||||
|
||||
// view definition with links (collection not authorized)
|
||||
{
|
||||
auto collectionJson = arangodb::velocypack::Parser::fromJson("{ \"name\": \"testCollection\", \"id\": 100 }");
|
||||
auto viewCreateJson = arangodb::velocypack::Parser::fromJson("{ \"name\": \"testView\", \"type\": \"arangosearch\" }");
|
||||
auto viewUpdateJson = arangodb::velocypack::Parser::fromJson("{ \"links\": { \"testCollection\": {} } }");
|
||||
|
||||
TRI_vocbase_t vocbase(TRI_vocbase_type_e::TRI_VOCBASE_TYPE_NORMAL, 1, "testVocbase");
|
||||
auto* logicalCollection = vocbase.createCollection(collectionJson->slice());
|
||||
REQUIRE((nullptr != logicalCollection));
|
||||
auto logicalView = vocbase.createView(viewCreateJson->slice());
|
||||
REQUIRE((false == !logicalView));
|
||||
|
||||
CHECK((true == logicalCollection->getIndexes().empty()));
|
||||
CHECK((true == logicalView->visitCollections([](TRI_voc_cid_t)->bool { return false; })));
|
||||
|
||||
CHECK((logicalView->updateProperties(viewUpdateJson->slice(), true, false).ok()));
|
||||
|
||||
CHECK((false == logicalCollection->getIndexes().empty()));
|
||||
CHECK((false == logicalView->visitCollections([](TRI_voc_cid_t)->bool { return false; })));
|
||||
|
||||
struct ExecContext: public arangodb::ExecContext {
|
||||
ExecContext(): arangodb::ExecContext(0, "", "", arangodb::auth::Level::NONE, arangodb::auth::Level::NONE) {}
|
||||
} execContext;
|
||||
auto* origExecContext = ExecContext::CURRENT;
|
||||
auto resetExecContext = irs::make_finally([origExecContext]()->void{ ExecContext::CURRENT = origExecContext; });
|
||||
ExecContext::CURRENT = &execContext;
|
||||
auto* authFeature = arangodb::AuthenticationFeature::instance();
|
||||
auto* userManager = authFeature->userManager();
|
||||
arangodb::auth::UserMap userMap; // empty map, no user -> no permissions
|
||||
userManager->setAuthInfo(userMap); // set user map to avoid loading configuration from system database
|
||||
auto resetUserManager = irs::make_finally([userManager]()->void{ userManager->removeAllUsers(); });
|
||||
|
||||
arangodb::iresearch::IResearchViewMeta expectedMeta;
|
||||
arangodb::velocypack::Builder builder;
|
||||
|
||||
builder.openObject();
|
||||
CHECK((TRI_ERROR_FORBIDDEN == logicalView->toVelocyPack(builder, true, false).errorNumber()));
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("test_drop") {
|
||||
|
|
|
@ -88,6 +88,11 @@ struct IResearchViewNodeSetup {
|
|||
// suppress INFO {authentication} Authentication is turned on (system only), authentication for unix sockets is turned on
|
||||
arangodb::LogTopic::setLogLevel(arangodb::Logger::AUTHENTICATION.name(), arangodb::LogLevel::WARN);
|
||||
|
||||
// suppress log messages since tests check error conditions
|
||||
arangodb::LogTopic::setLogLevel(arangodb::Logger::FIXME.name(), arangodb::LogLevel::ERR); // suppress WARNING DefaultCustomTypeHandler called
|
||||
arangodb::LogTopic::setLogLevel(arangodb::iresearch::TOPIC.name(), arangodb::LogLevel::FATAL);
|
||||
irs::logger::output_le(iresearch::logger::IRL_FATAL, stderr);
|
||||
|
||||
// setup required application features
|
||||
features.emplace_back(new arangodb::ViewTypesFeature(&server), true);
|
||||
features.emplace_back(new arangodb::AuthenticationFeature(&server), true);
|
||||
|
@ -121,11 +126,6 @@ struct IResearchViewNodeSetup {
|
|||
f.first->start();
|
||||
}
|
||||
}
|
||||
|
||||
// suppress log messages since tests check error conditions
|
||||
arangodb::LogTopic::setLogLevel(arangodb::Logger::FIXME.name(), arangodb::LogLevel::ERR); // suppress WARNING DefaultCustomTypeHandler called
|
||||
arangodb::LogTopic::setLogLevel(arangodb::iresearch::TOPIC.name(), arangodb::LogLevel::FATAL);
|
||||
irs::logger::output_le(iresearch::logger::IRL_FATAL, stderr);
|
||||
}
|
||||
|
||||
~IResearchViewNodeSetup() {
|
||||
|
|
Loading…
Reference in New Issue