8000 restrict database length to 64 characters again (#10713) · nginxpre/arangodb@09e80ff · GitHub
[go: up one dir, main page]

Skip to content

Commit 09e80ff

Browse files
authored
restrict database length to 64 characters again (arangodb#10713)
1 parent a9d4252 commit 09e80ff

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

arangod/VocBase/Methods/Collections.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,13 +339,13 @@ Result Collections::create(TRI_vocbase_t& vocbase,
339339
VPackBuilder merged =
340340
VPackCollection::merge(info.properties, helper.slice(), false, true);
341341

342-
if (haveShardingFeature && !info.properties.get("shardingStrategy").isString()) {
342+
if (haveShardingFeature && !info.properties.get(StaticStrings::ShardingStrategy).isString()) {
343343
// NOTE: We need to do this in a second merge as the geature call requires to have the
344344
// DataSourceType set in the JSON, which has just been done by the call above.
345345
helper.clear();
346346
helper.openObject();
347347
TRI_ASSERT(ServerState::instance()->isCoordinator());
348-
helper.add("shardingStrategy",
348+
helper.add(StaticStrings::ShardingStrategy,
349349
VPackValue(vocbase.server().getFeature<ShardingFeature>().getDefaultShardingStrategyForNewCollection(
350350
merged.slice())));
351351
helper.close();

arangod/VocBase/VocbaseInfo.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,12 @@ Result CreateDatabaseInfo::checkOptions() {
287287
_validId = false;
288288
}
289289

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

tests/js/common/shell/01_shell-database.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,29 @@ function DatabaseSuite () {
8585
assertTrue(internal.db._dropDatabase("UnitTestsDatabase1"));
8686
},
8787

88+
////////////////////////////////////////////////////////////////////////////////
89+
/// @brief test create with too long names function
90+
////////////////////////////////////////////////////////////////////////////////
91+
92+
testLongName : function () {
93+
const prefix = "UnitTestsDatabase";
94+
let name = prefix + Array(64 + 1 - prefix.length).join("x");
95+
assertEqual(64, name.length);
96+
97+
assertTrue(internal.db._createDatabase(name));
98+
assertTrue(internal.db._dropDatabase(name));
99+
100+
name += 'x';
101+
assertEqual(65, name.length);
102+
103+
try {
104+
internal.db._createDatabase(name);
105+
fail();
106+
} catch (err) {
107+
assertEqual(ERRORS.ERROR_ARANGO_DATABASE_NAME_INVALID.code, err.errorNum);
108+
}
109+
},
110+
88111
////////////////////////////////////////////////////////////////////////////////
89112
/// @brief test _name function
90113
////////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)
0