Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

restrict database length to 64 characters again #10712

Merged
merged 1 commit into from
Dec 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions arangod/VocBase/Methods/Collections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,13 +339,13 @@ Result Collections::create(TRI_vocbase_t& vocbase,
VPackBuilder merged =
VPackCollection::merge(info.properties, helper.slice(), false, true);

if (haveShardingFeature && !info.properties.get("shardingStrategy").isString()) {
if (haveShardingFeature && !info.properties.get(StaticStrings::ShardingStrategy).isString()) {
// NOTE: We need to do this in a second merge as the geature call requires to have the
// DataSourceType set in the JSON, which has just been done by the call above.
helper.clear();
helper.openObject();
TRI_ASSERT(ServerState::instance()->isCoordinator());
helper.add("shardingStrategy",
helper.add(StaticStrings::ShardingStrategy,
VPackValue(vocbase.server().getFeature<ShardingFeature>().getDefaultShardingStrategyForNewCollection(
merged.slice())));
helper.close();
Expand Down
6 changes: 5 additions & 1 deletion arangod/VocBase/VocbaseInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,12 @@ Result CreateDatabaseInfo::checkOptions() {
_validId = false;
}

// we cannot use IsAllowedName for database name length validation alone, because
// IsAllowedName allows up to 256 characters. Database names are just up to 64
// chars long, as their names are also used as filesystem directories (for Foxx apps)
if (_name.empty() ||
!TRI_vocbase_t::IsAllowedName(_isSystemDB, arangodb::velocypack::StringRef(_name))) {
!TRI_vocbase_t::IsAllowedName(_isSystemDB, arangodb::velocypack::StringRef(_name)) ||
_name.size() > 64) {
return Result(TRI_ERROR_ARANGO_DATABASE_NAME_INVALID);
}

Expand Down
23 changes: 23 additions & 0 deletions tests/js/common/shell/01_shell-database.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,29 @@ function DatabaseSuite () {
assertTrue(internal.db._dropDatabase("UnitTestsDatabase1"));
},

////////////////////////////////////////////////////////////////////////////////
/// @brief test create with too long names function
////////////////////////////////////////////////////////////////////////////////

testLongName : function () {
const prefix = "UnitTestsDatabase";
let name = prefix + Array(64 + 1 - prefix.length).join("x");
assertEqual(64, name.length);

assertTrue(internal.db._createDatabase(name));
assertTrue(internal.db._dropDatabase(name));

name += 'x';
assertEqual(65, name.length);

try {
internal.db._createDatabase(name);
fail();
} catch (err) {
assertEqual(ERRORS.ERROR_ARANGO_DATABASE_NAME_INVALID.code, err.errorNum);
}
},

////////////////////////////////////////////////////////////////////////////////
/// @brief test _name function
////////////////////////////////////////////////////////////////////////////////
Expand Down