Skip to content

Commit a5e943d

Browse files
authored
feat: Fail if standard beacon used with not equal (#198)
1 parent e983f8f commit a5e943d

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed

DynamoDbEncryption/dafny/DynamoDbEncryption/src/FilterExpr.dfy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ module DynamoDBFilterExpr {
244244
ensures ret.Success? ==> ret.value
245245
{
246246
match op {
247-
case Lt | Gt | Le | Ge | Between | BeginsWith | Contains =>
247+
case Ne | Lt | Gt | Le | Ge | Between | BeginsWith | Contains =>
248248
Failure(E("The operation '" + TokenToString(op) + "' cannot be used with a standard beacon."))
249249
case _ => Success(true)
250250
}

DynamoDbEncryption/dafny/DynamoDbEncryption/test/FilterExpr.dfy

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ module TestDynamoDBFilterExpr {
9595
method {:test} TestBasicParse() {
9696
var context := ExprContext (
9797
None,
98-
Some("std2 <> :A AND #Field4 = :B"),
98+
Some("std2 = :A AND #Field4 = :B"),
9999
Some(map[
100100
":A" := DDB.AttributeValue.N("1.23"),
101101
":B" := DDB.AttributeValue.S("abc")
@@ -117,13 +117,13 @@ module TestDynamoDBFilterExpr {
117117

118118
var newContext :- expect BeaconizeParsedExpr(beaconVersion, parsed, 0, context.values.value, context.names, DontUseKeys, map[]);
119119
var exprString := ParsedExprToString(newContext.expr);
120-
expect exprString == "aws_dbe_b_std2 <> :A AND #Field4 = :B";
120+
expect exprString == "aws_dbe_b_std2 = :A AND #Field4 = :B";
121121
}
122122

123123
method {:test} TestNoBeaconFail() {
124124
var context := ExprContext (
125125
None,
126-
Some("std2 <> :A AND #Field4 = :B"),
126+
Some("std2 = :A AND #Field4 = :B"),
127127
Some(map[
128128
":A" := DDB.AttributeValue.N("1.23"),
129129
":B" := DDB.AttributeValue.S("abc")
@@ -150,15 +150,15 @@ module TestDynamoDBFilterExpr {
150150
var badBeacon := TestBeaconize(FullTableConfig.attributeActions, None, Some("std2 <> :A AND #Field4 = :B"), None);
151151
expect badBeacon.Failure?;
152152
expect badBeacon.error == E("Query is using encrypted field : std2.");
153-
badBeacon := TestBeaconize(FullTableConfig.attributeActions, Some("std2 <> :A AND #Field4 = :B"), None, None);
153+
badBeacon := TestBeaconize(FullTableConfig.attributeActions, Some("std2 = :A AND #Field4 = :B"), None, None);
154154
expect badBeacon.Failure?;
155155
expect badBeacon.error == E("Query is using encrypted field : std2.");
156156
}
157157

158158
method {:test} {:vcs_split_on_every_assert} TestBasicBeacons() {
159159
var context := ExprContext (
160160
None,
161-
Some("std2 <> :A AND #Field4 = :B"),
161+
Some("std2 = :A AND #Field4 = :B"),
162162
Some(map[
163163
":A" := Std2String,
164164
":B" := Std4String
@@ -171,7 +171,7 @@ module TestDynamoDBFilterExpr {
171171
var src := GetLiteralSource([1,2,3,4,5], version);
172172
var beaconVersion :- expect ConvertVersionWithSource(FullTableConfig, version, src);
173173
var newContext :- expect Beaconize(beaconVersion, context, DontUseKeyId);
174-
expect_equal(newContext.filterExpr, Some("aws_dbe_b_std2 <> :A AND #Field4 = :B"));
174+
expect_equal(newContext.filterExpr, Some("aws_dbe_b_std2 = :A AND #Field4 = :B"));
175175
var newName := "aws_dbe_b_std4";
176176
expect IsValid_AttributeName(newName);
177177
var expectedNames: DDB.ExpressionAttributeNameMap := map["#Field4" := newName];
@@ -581,6 +581,34 @@ module TestDynamoDBFilterExpr {
581581
expect newItems.error == E("To use BETWEEN with a compound beacon, the part after any common prefix must be LessThanComparable : BETWEEN T_ATitle AND T_MyTitle");
582582
}
583583

584+
method {:test} TestBadStandard() {
585+
586+
var values : DDB.ExpressionAttributeValueMap := map [
587+
":val" := DS("foo")
588+
];
589+
590+
var version := GetLotsaBeacons();
591+
var src := GetLiteralSource([1,2,3,4,5], version);
592+
var bv :- expect ConvertVersionWithSource(FullTableConfig, version, src);
593+
var newItems := FilterResults(bv, [SimpleItem], None, Some("std2 = :val"), None, Some(values));
594+
expect newItems.Success?;
595+
newItems := FilterResults(bv, [SimpleItem], None, Some("std2 <> :val"), None, Some(values));
596+
expect newItems.Failure?;
597+
expect newItems.error == E("The operation '<>' cannot be used with a standard beacon.");
598+
newItems := FilterResults(bv, [SimpleItem], None, Some("std2 < :val"), None, Some(values));
599+
expect newItems.Failure?;
600+
expect newItems.error == E("The operation '<' cannot be used with a standard beacon.");
601+
newItems := FilterResults(bv, [SimpleItem], None, Some("std2 > :val"), None, Some(values));
602+
expect newItems.Failure?;
603+
expect newItems.error == E("The operation '>' cannot be used with a standard beacon.");
604+
newItems := FilterResults(bv, [SimpleItem], None, Some("std2 <= :val"), None, Some(values));
605+
expect newItems.Failure?;
606+
expect newItems.error == E("The operation '<=' cannot be used with a standard beacon.");
607+
newItems := FilterResults(bv, [SimpleItem], None, Some("std2 >= :val"), None, Some(values));
608+
expect newItems.Failure?;
609+
expect newItems.error == E("The operation '>=' cannot be used with a standard beacon.");
610+
}
611+
584612
method {:test} TestComparisons() {
585613

586614
var values : DDB.ExpressionAttributeValueMap := map [

0 commit comments

Comments
 (0)