diff --git a/assets/ObfuscatorTest.pbix b/assets/ObfuscatorTest.pbix new file mode 100644 index 0000000..e8b9a11 Binary files /dev/null and b/assets/ObfuscatorTest.pbix differ diff --git a/tests/Dax.Vpax.Obfuscator.Tests/DaxModelDeobfuscatorTests.cs b/tests/Dax.Vpax.Obfuscator.Tests/DaxModelDeobfuscatorTests.cs index 5553e4b..035ad1b 100644 --- a/tests/Dax.Vpax.Obfuscator.Tests/DaxModelDeobfuscatorTests.cs +++ b/tests/Dax.Vpax.Obfuscator.Tests/DaxModelDeobfuscatorTests.cs @@ -1,10 +1,6 @@ -using System.Collections.Generic; -using System.Globalization; -using System.Linq.Expressions; -using Dax.Metadata; +using Dax.Metadata; using Dax.Vpax.Obfuscator.Common; using Dax.Vpax.Obfuscator.Tests.TestUtils; -using Dax.Tokenizer; using Xunit; namespace Dax.Vpax.Obfuscator.Tests; @@ -51,8 +47,8 @@ public void DeobfuscateExpression_CalendarDateColumn_IsNotDeobfuscatedBecauseItI [Fact] public void DeobfuscateExpression_TableConstructorColumnName_IsNotDeobfuscatedBecauseItIsNotObfuscated_SingleColumnTest() { - var expression = """ SELECTCOLUMNS({ (0) }, "XXX", [Value]) """; - var expected = """ SELECTCOLUMNS({ (0) }, "@c1", [Value]) """; + var expression = """ SELECTCOLUMNS({0}, "XXX", [Value]) """; + var expected = """ SELECTCOLUMNS({0}, "@c1", [Value]) """; var (_, _, deobfuscator) = CreateTest( [ @@ -66,8 +62,8 @@ public void DeobfuscateExpression_TableConstructorColumnName_IsNotDeobfuscatedBe [Fact] public void DeobfuscateExpression_TableConstructorColumnName_IsNotDeobfuscatedBecauseItIsNotObfuscated_MultipleColumnsTest() { - var expression = """ SELECTCOLUMNS({ (1,2,3) }, "XXX", [Value1], "YYY", [value2], "ZZZ", [VALUE3]) """; - var expected = """ SELECTCOLUMNS({ (1,2,3) }, "@c1", [Value1], "@c2", [value2], "@c3", [VALUE3]) """; + var expression = """ SELECTCOLUMNS({(1,2,3)}, "XXX", [Value1], "YYY", [value2], "ZZZ", [VALUE3]) """; + var expected = """ SELECTCOLUMNS({(1,2,3)}, "@c1", [Value1], "@c2", [value2], "@c3", [VALUE3]) """; var (_, _, deobfuscator) = CreateTest( [ @@ -81,14 +77,13 @@ public void DeobfuscateExpression_TableConstructorColumnName_IsNotDeobfuscatedBe } [Fact] - public void DeobfuscateExpression_ExtensionColumnNameWithDifferentCasings_ReturnsSameDeobfuscatedValue() + public void DeobfuscateExpression_ExtensionColumnNameMultipleReferencesWithDifferentCasings_ReturnsSameDeobfuscatedValue() { - var expression = """ SUMX(ADDCOLUMNS(Date, "XXXXXXX", 1), [XXXXXXX]) """; - var expected = """ SUMX(ADDCOLUMNS(Date, "@column", 1), [@COLUMN]) """; + var expression = """ SUMX(ADDCOLUMNS({}, "XXXXXXX", 1), [XXXXXXX]) """; + var expected = """ SUMX(ADDCOLUMNS({}, "@column", 1), [@COLUMN]) """; var (_, _, deobfuscator) = CreateTest( [ - new ObfuscationText("Date", "Date"), new ObfuscationText("@column", "XXXXXXX"), ]); var actual = deobfuscator.DeobfuscateExpression(expression); @@ -97,15 +92,14 @@ public void DeobfuscateExpression_ExtensionColumnNameWithDifferentCasings_Return } [Fact] - public void DeobfuscateExpression_ExtensionColumnName_ReturnsDeobfuscatedTableNameAndColumnNameParts() + public void DeobfuscateExpression_ExtensionColumnNameFullyQualified_ReturnsDeobfuscatedColumnNameParts() { - var expression = """ SUMX(ADDCOLUMNS(Date, "XXXXXX[Y]", 1), XXXXXX[Y]) """; - var expected = """ SUMX(ADDCOLUMNS(Date, "__rate[%]", 1), __rate[%]) """; + var expression = """ SUMX(ADDCOLUMNS({}, "XXXX[Y]", 1), XXXX[Y]) """; + var expected = """ SUMX(ADDCOLUMNS({}, "rate[%]", 1), rate[%]) """; var (_, _, deobfuscator) = CreateTest( [ - new ObfuscationText("Date", "Date"), - new ObfuscationText("__rate", "XXXXXX"), + new ObfuscationText("rate", "XXXX"), new ObfuscationText("%", "Y"), ]); var actual = deobfuscator.DeobfuscateExpression(expression); @@ -114,14 +108,13 @@ public void DeobfuscateExpression_ExtensionColumnName_ReturnsDeobfuscatedTableNa } [Fact] - public void DeobfuscateExpression_ExtensionColumnName_ReturnsDeobfuscatedValuePreservingEscapeChar() + public void DeobfuscateExpression_ExtensionColumnNameFullyQualified_ReturnsDeobfuscatedColumnNamePartsPreservingQuotationMarkEscapeChar() { - var expression = """ SELECTCOLUMNS(ADDCOLUMNS(Date, "XXX[Y""Y]", 1), XXX[Y"Y]) """; - var expected = """ SELECTCOLUMNS(ADDCOLUMNS(Date, "aaa[b""c]", 1), aaa[b"c]) """; + var expression = """ SELECTCOLUMNS(ADDCOLUMNS({}, "XXX[Y""Y]", 1), XXX[Y"Y]) """; + var expected = """ SELECTCOLUMNS(ADDCOLUMNS({}, "aaa[b""c]", 1), aaa[b"c]) """; var (_, _, deobfuscator) = CreateTest( [ - new ObfuscationText("Date", "Date"), new ObfuscationText("aaa", "XXX"), new ObfuscationText("b\"c", "Y\"Y"), ]); @@ -131,7 +124,7 @@ public void DeobfuscateExpression_ExtensionColumnName_ReturnsDeobfuscatedValuePr } [Fact] - public void DeobfuscateExpression_TableNameWithDifferentCasings_ReturnsSameDeobfuscatedValue() + public void DeobfuscateExpression_TableNameMultipleReferencesWithDifferentCasings_ReturnsSameDeobfuscatedValue() { var expression = "COUNTROWS('XXXXX') + COUNTROWS(XXXXX) + COUNTROWS(XXXXX) + COUNTROWS(XXXXX)"; var expected = "COUNTROWS('Sales') + COUNTROWS(sales) + COUNTROWS(SALES) + COUNTROWS(SaLeS)"; @@ -146,7 +139,7 @@ public void DeobfuscateExpression_TableNameWithDifferentCasings_ReturnsSameDeobf } [Fact] - public void DeobfuscateExpression_ColumnNameWithEscapeSquareBracket_ReturnsDeobfuscatedValuePreservingEscapeChar() + public void DeobfuscateExpression_ColumnName_ReturnsDeobfuscatedValuePreservingSquareBracketEscapeChar() { var expression = "RELATED( XXXXX[YYYYYY]]] )"; var expected = "RELATED( Sales[Rate[%]]] )"; @@ -162,7 +155,7 @@ public void DeobfuscateExpression_ColumnNameWithEscapeSquareBracket_ReturnsDeobf } [Fact] - public void DeobfuscateExpression_VariableNameWithDifferentCasings_ReturnsSameDeobfuscatedValue() + public void DeobfuscateExpression_VariableNameMultipleReferencesWithDifferentCasings_ReturnsSameDeobfuscatedValue() { var expression = "VAR XXXXXX = 1 RETURN XXXXXX + XXXXXX + XXXXXX"; var expected = "VAR Amount = 1 RETURN AMOUNT + AmOuNt + amount"; @@ -179,8 +172,8 @@ public void DeobfuscateExpression_VariableNameWithDifferentCasings_ReturnsSameDe [Fact] public void ObfuscateExpression_ValueExtensionColumnName_IsNotObfuscated() { - var expression = """ SELECTCOLUMNS ( { 1 }, "XXXXXXXXXX", ''[Value]) """; - var expected = """ SELECTCOLUMNS ( { 1 }, "__Measures", ''[Value]) """; + var expression = """ SELECTCOLUMNS({0}, "XXXXXXXXXX", ''[Value]) """; + var expected = """ SELECTCOLUMNS({0}, "__Measures", ''[Value]) """; var (_, _, deobfuscator) = CreateTest( [ diff --git a/tests/Dax.Vpax.Obfuscator.Tests/DaxModelObfuscatorTests.cs b/tests/Dax.Vpax.Obfuscator.Tests/DaxModelObfuscatorTests.cs index cf39476..4977c40 100644 --- a/tests/Dax.Vpax.Obfuscator.Tests/DaxModelObfuscatorTests.cs +++ b/tests/Dax.Vpax.Obfuscator.Tests/DaxModelObfuscatorTests.cs @@ -42,8 +42,8 @@ public void ObfuscateExpression_CalendarDateColumn_IsNotObfuscated() [Fact] public void ObfuscateExpression_TableConstructorColumnName_IsNotObfuscated_SingleColumnTest() { - var expression = """ SELECTCOLUMNS({ (0) }, "@c1", [Value]) """; - var expected = """ SELECTCOLUMNS({ (0) }, "XXX", [Value]) """; + var expression = """ SELECTCOLUMNS({0}, "@c1", [Value]) """; + var expected = """ SELECTCOLUMNS({0}, "XXX", [Value]) """; var obfuscator = new DaxModelObfuscator(new Model()); obfuscator.Texts.Add(new DaxText("@c1", "XXX")); @@ -55,8 +55,8 @@ public void ObfuscateExpression_TableConstructorColumnName_IsNotObfuscated_Singl [Fact] public void ObfuscateExpression_TableConstructorColumnName_IsNotObfuscated_MultipleColumnsTest() { - var expression = """ SELECTCOLUMNS({ (1,2,3) }, "@c1", [Value1], "@c2", [value2], "@c3", [VALUE3]) """; - var expected = """ SELECTCOLUMNS({ (1,2,3) }, "XXX", [Value1], "YYY", [value2], "ZZZ", [VALUE3]) """; + var expression = """ SELECTCOLUMNS({(1,2,3)}, "@c1", [Value1], "@c2", [value2], "@c3", [VALUE3]) """; + var expected = """ SELECTCOLUMNS({(1,2,3)}, "XXX", [Value1], "YYY", [value2], "ZZZ", [VALUE3]) """; var obfuscator = new DaxModelObfuscator(new Model()); obfuscator.Texts.Add(new DaxText("@c1", "XXX")); @@ -68,10 +68,10 @@ public void ObfuscateExpression_TableConstructorColumnName_IsNotObfuscated_Multi } [Fact] - public void ObfuscateExpression_ExtensionColumnNameWithDifferentCasings_ReturnsSameObfuscatedValue() + public void ObfuscateExpression_ExtensionColumnNameMultipleReferencesWithDifferentCasings_ReturnsSameObfuscatedValue() { - var expression = """ SUMX(ADDCOLUMNS(Date, "@column", 1), [@COLUMN]) """; - var expected = """ SUMX(ADDCOLUMNS(Date, "XXXXXXX", 1), [XXXXXXX]) """; + var expression = """ SUMX(ADDCOLUMNS({}, "@column", 1), [@COLUMN]) """; + var expected = """ SUMX(ADDCOLUMNS({}, "XXXXXXX", 1), [XXXXXXX]) """; var obfuscator = new DaxModelObfuscator(new Model()); obfuscator.Texts.Add(new DaxText("@column", "XXXXXXX")); @@ -81,13 +81,13 @@ public void ObfuscateExpression_ExtensionColumnNameWithDifferentCasings_ReturnsS } [Fact] - public void ObfuscateExpression_ExtensionColumnName_ReturnsObfuscatedTableNameAndColumnNameParts() + public void ObfuscateExpression_ExtensionColumnNameFullyQualified_ReturnsObfuscatedColumnNameParts() { - var expression = """ SUMX(ADDCOLUMNS(Date, "__rate[%]", 1), __rate[%]) """; - var expected = """ SUMX(ADDCOLUMNS(Date, "XXXXXX[Y]", 1), XXXXXX[Y]) """; + var expression = """ SUMX(ADDCOLUMNS({}, "rate[%]", 1), rate[%]) """; + var expected = """ SUMX(ADDCOLUMNS({}, "XXXX[Y]", 1), XXXX[Y]) """; var obfuscator = new DaxModelObfuscator(new Model()); - obfuscator.Texts.Add(new DaxText("__rate", "XXXXXX")); + obfuscator.Texts.Add(new DaxText("rate", "XXXX")); obfuscator.Texts.Add(new DaxText("%", "Y")); var actual = obfuscator.ObfuscateExpression(expression); @@ -95,10 +95,10 @@ public void ObfuscateExpression_ExtensionColumnName_ReturnsObfuscatedTableNameAn } [Fact] - public void ObfuscateExpression_ExtensionColumnName_ReturnsObfuscatedValuePreservingEscapeChar() + public void ObfuscateExpression_ExtensionColumnNameFullyQualified_ReturnsObfuscatedColumnNamePartsPreservingQuotationMarkEscapeChar() { - var expression = """ SELECTCOLUMNS(ADDCOLUMNS(Date, "aaa[b""c]", 1), aaa[b"c]) """; - var expected = """ SELECTCOLUMNS(ADDCOLUMNS(Date, "XXX[Y""Y]", 1), XXX[Y"Y]) """; + var expression = """ SELECTCOLUMNS(ADDCOLUMNS({}, "aaa[b""c]", 1), aaa[b"c]) """; + var expected = """ SELECTCOLUMNS(ADDCOLUMNS({}, "XXX[Y""Y]", 1), XXX[Y"Y]) """; var obfuscator = new DaxModelObfuscator(new Model()); obfuscator.Texts.Add(new DaxText("aaa", "XXX")); @@ -122,7 +122,7 @@ public void ObfuscateExpression_TableNameWithDifferentCasings_ReturnsSameObfusca } [Fact] - public void ObfuscateExpression_ColumnNameWithEscapeSquareBracket_ReturnsObfuscatedValuePreservingEscapeChar() + public void ObfuscateExpression_ColumnName_ReturnsObfuscatedValuePreservingSquareBracketEscapeChar() { var expression = "RELATED( Sales[Rate[%]]] )"; var expected = "RELATED( XXXXX[YYYYYY]]] )"; @@ -136,7 +136,7 @@ public void ObfuscateExpression_ColumnNameWithEscapeSquareBracket_ReturnsObfusca } [Fact] - public void ObfuscateExpression_VariableNameWithDifferentCasings_ReturnsSameObfuscatedValue() + public void ObfuscateExpression_VariableNameMultipleReferencesWithDifferentCasings_ReturnsSameObfuscatedValue() { var expression = "VAR Amount = 1 RETURN AMOUNT + AmOuNt + amount"; var expected = "VAR XXXXXX = 1 RETURN XXXXXX + XXXXXX + XXXXXX"; @@ -151,8 +151,8 @@ public void ObfuscateExpression_VariableNameWithDifferentCasings_ReturnsSameObfu [Fact] public void ObfuscateExpression_ValueExtensionColumnName_IsNotObfuscated() { - var expression = """ SELECTCOLUMNS ( { 1 }, "__Measures", ''[Value]) """; - var expected = """ SELECTCOLUMNS ( { 1 }, "XXXXXXXXXX", ''[Value]) """; + var expression = """ SELECTCOLUMNS({0}, "__Measures", ''[Value]) """; + var expected = """ SELECTCOLUMNS({0}, "XXXXXXXXXX", ''[Value]) """; var obfuscator = new DaxModelObfuscator(new Model()); obfuscator.Texts.Add(new DaxText("__Measures", "XXXXXXXXXX"));