mirror of https://github.com/apache/cassandra
add more robust sanity checking of get_column arguments. patch by jbellis; reviewed by Jun Rao for CASSANDRA-151
git-svn-id: https://svn.apache.org/repos/asf/incubator/cassandra/trunk@773016 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
85a121b474
commit
f2260f107b
|
|
@ -212,11 +212,27 @@ public class CassandraServer implements Cassandra.Iface
|
|||
{
|
||||
logger.debug("get_column");
|
||||
String[] values = RowMutation.getColumnAndColumnFamily(columnFamily_column);
|
||||
if (values.length < 2)
|
||||
if (values.length < 1)
|
||||
{
|
||||
throw new InvalidRequestException("get_column requires both parts of columnfamily:column");
|
||||
throw new InvalidRequestException("get_column requires non-empty columnfamily");
|
||||
}
|
||||
ColumnFamily cfamily = readColumnFamily(new ColumnReadCommand(tablename, key, columnFamily_column));
|
||||
if (DatabaseDescriptor.getColumnFamilyType(values[0]).equals("Standard"))
|
||||
{
|
||||
if (values.length != 2)
|
||||
{
|
||||
throw new InvalidRequestException("get_column requires both parts of columnfamily:column for standard CF " + values[0]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (values.length != 3)
|
||||
{
|
||||
throw new InvalidRequestException("get_column requires all parts of columnfamily:supercolumn:subcolumn for super CF " + values[0]);
|
||||
}
|
||||
}
|
||||
|
||||
ColumnReadCommand readCommand = new ColumnReadCommand(tablename, key, columnFamily_column);
|
||||
ColumnFamily cfamily = readColumnFamily(readCommand);
|
||||
if (cfamily == null)
|
||||
{
|
||||
throw new NotFoundException();
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import os, sys, time
|
|||
from . import client, root, CassandraTester
|
||||
|
||||
from thrift.Thrift import TApplicationException
|
||||
from ttypes import batch_mutation_t, batch_mutation_super_t, superColumn_t, column_t, NotFoundException
|
||||
from ttypes import batch_mutation_t, batch_mutation_super_t, superColumn_t, column_t, NotFoundException, InvalidRequestException
|
||||
|
||||
_SIMPLE_COLUMNS = [column_t(columnName='c1', value='value1', timestamp=0),
|
||||
column_t(columnName='c2', value='value2', timestamp=0)]
|
||||
|
|
@ -45,13 +45,15 @@ def _verify_super(supercolumn='Super1'):
|
|||
slice = client.get_slice_super('Table1', 'key1', 'Super1', -1, -1)
|
||||
assert slice == _SUPER_COLUMNS, slice
|
||||
|
||||
def _expect_missing(fn):
|
||||
def _expect_exception(fn, type_):
|
||||
try:
|
||||
r = fn()
|
||||
except NotFoundException:
|
||||
except type_:
|
||||
pass
|
||||
else:
|
||||
raise Exception('expected missing result; got %s' % r)
|
||||
raise Exception('expected %s; got %s' % (type_.__name__, r))
|
||||
def _expect_missing(fn):
|
||||
_expect_exception(fn, NotFoundException)
|
||||
|
||||
|
||||
class TestMutations(CassandraTester):
|
||||
|
|
@ -62,7 +64,7 @@ class TestMutations(CassandraTester):
|
|||
assert client.get_slice('Table1', 'key1', 'Super1', -1, -1) == []
|
||||
|
||||
def test_missing_super(self):
|
||||
_expect_missing(lambda: client.get_column('Table1', 'key1', 'Super1:sc1'))
|
||||
_expect_missing(lambda: client.get_column('Table1', 'key1', 'Super1:sc1:c1'))
|
||||
|
||||
def test_count(self):
|
||||
assert client.get_column_count('Table1', 'key1', 'Standard2') == 0
|
||||
|
|
@ -89,6 +91,13 @@ class TestMutations(CassandraTester):
|
|||
_insert_batch(True)
|
||||
_verify_batch()
|
||||
|
||||
def test_bad_gets(self):
|
||||
_expect_exception(lambda: client.get_column('Table1', 'key1', 'Standard1'), InvalidRequestException)
|
||||
_expect_exception(lambda: client.get_column('Table1', 'key1', 'Standard1:x:y'), InvalidRequestException)
|
||||
_expect_exception(lambda: client.get_column('Table1', 'key1', 'Super1'), InvalidRequestException)
|
||||
_expect_exception(lambda: client.get_column('Table1', 'key1', 'Super1:x'), InvalidRequestException)
|
||||
_expect_exception(lambda: client.get_column('Table1', 'key1', 'Super1:x:y:z'), InvalidRequestException)
|
||||
|
||||
def test_batch_insert_super(self):
|
||||
cfmap = {'Super1': _SUPER_COLUMNS,
|
||||
'Super2': _SUPER_COLUMNS}
|
||||
|
|
|
|||
Loading…
Reference in New Issue