From e8a63c11bdbe65976cc12c4441e566e0493df76e Mon Sep 17 00:00:00 2001 From: CelsoSimoes <48064998+CelsoSimoes@users.noreply.github.com> Date: Thu, 15 Oct 2020 16:05:48 -0300 Subject: [PATCH 1/3] tests: Adding new syntax tests --- .../fixtures/syntax-error/error-1/Main.hp | 16 +++++++ .../fixtures/syntax-error/error-1/Syntax.hp | 21 +++++++++ .../fixtures/syntax-error/error-2/Main.hp | 30 +++++++++++++ .../fixtures/syntax-error/error-2/Syntax.hp | 21 +++++++++ .../fixtures/syntax-error/error-3/Main.hp | 25 +++++++++++ .../fixtures/syntax-error/error-3/Syntax.hp | 21 +++++++++ .../fixtures/syntax-error/error-4/Main.hp | 29 ++++++++++++ .../fixtures/syntax-error/error-4/Syntax.hp | 17 +++++++ src/test/kotlin/VisitorTest.kt | 44 +++++++++++++++++++ 9 files changed, 224 insertions(+) create mode 100644 src/test/fixtures/syntax-error/error-1/Main.hp create mode 100644 src/test/fixtures/syntax-error/error-1/Syntax.hp create mode 100644 src/test/fixtures/syntax-error/error-2/Main.hp create mode 100644 src/test/fixtures/syntax-error/error-2/Syntax.hp create mode 100644 src/test/fixtures/syntax-error/error-3/Main.hp create mode 100644 src/test/fixtures/syntax-error/error-3/Syntax.hp create mode 100644 src/test/fixtures/syntax-error/error-4/Main.hp create mode 100644 src/test/fixtures/syntax-error/error-4/Syntax.hp diff --git a/src/test/fixtures/syntax-error/error-1/Main.hp b/src/test/fixtures/syntax-error/error-1/Main.hp new file mode 100644 index 0000000..9f83c9a --- /dev/null +++ b/src/test/fixtures/syntax-error/error-1/Main.hp @@ -0,0 +1,16 @@ +import Syntax; +// Esse teste PASSA. (Baseado no WrongName) +//Caso teste- Erro de sintaxe 1: +// Deve retornar um erro devido ao nome do Actor dentro da +// variavel jeff estar errado. + +main = + DENY + EXCEPT { + ALLOW { + Actors: Analyst + Resources + Actions + } + ALLOW Syntax::jeff + }; \ No newline at end of file diff --git a/src/test/fixtures/syntax-error/error-1/Syntax.hp b/src/test/fixtures/syntax-error/error-1/Syntax.hp new file mode 100644 index 0000000..ed14861 --- /dev/null +++ b/src/test/fixtures/syntax-error/error-1/Syntax.hp @@ -0,0 +1,21 @@ +export Syntax where + +data Actors = + Looker(Analyst), + Analyst(Alice, Bob), + Intern(Bob, Jeff), + Alice, Bob, Jeff; + +data Actions = Reads, Deletes, Updates; + +data Resources = + Claims(Finance), + Finance(Customers, Companies), + Customers(CCN), Companies(EMAIL, SSN), + CCN, EMAIL, SSN; + +jeff = ALLOW { + Actors: Jefa // Nome incorreto + Resources: CCN + Actions: Reads + }; \ No newline at end of file diff --git a/src/test/fixtures/syntax-error/error-2/Main.hp b/src/test/fixtures/syntax-error/error-2/Main.hp new file mode 100644 index 0000000..29357b9 --- /dev/null +++ b/src/test/fixtures/syntax-error/error-2/Main.hp @@ -0,0 +1,30 @@ +import Syntax; + +// Caso teste- Erro de sintaxe 2: +// A IR gerado admite que a Actor Alice execute a Action Reads +// no arquivo CCN, mesmo estando declarado DENY na variavel +// 'alice'. +// Isso deveria gerar um erro de Sintaxe ou gerar uma IR que negue +// o acesso por Read de Alice ao CCN. Contudo, somente um aviso está sendo gerado: +// "line 24:4 extraneous input 'DENY' expecting {'}', 'ALLOW'}" +// Em adendo, mesmo se removermos o ALLOW abaixo, antes da variável +// 'Syntax::alice', a linguagem ira interpretar que a query dentro +// da variavel é ALLOWed. + +main = + DENY + EXCEPT { + ALLOW { + Actors: Analyst + Resources + Actions + } + EXCEPT { + DENY { + Actors: Bob + Resources: EMAIL + Actions: Deletes, Updates, Reads + } + } + ALLOW Syntax::alice + }; \ No newline at end of file diff --git a/src/test/fixtures/syntax-error/error-2/Syntax.hp b/src/test/fixtures/syntax-error/error-2/Syntax.hp new file mode 100644 index 0000000..1876ce0 --- /dev/null +++ b/src/test/fixtures/syntax-error/error-2/Syntax.hp @@ -0,0 +1,21 @@ +export Syntax where + +data Actors = + Looker(Analyst), + Analyst(Alice, Bob), + Intern(Bob, Jeff), + Alice, Bob, Jeff; + +data Actions = Reads, Deletes, Updates; + +data Resources = + Claims(Finance), + Finance(Customers, Companies), + Customers(CCN), Companies(EMAIL, SSN), + CCN, EMAIL, SSN; + +alice = DENY { + Actors: Alice + Resources: CCN + Actions: Reads + }; \ No newline at end of file diff --git a/src/test/fixtures/syntax-error/error-3/Main.hp b/src/test/fixtures/syntax-error/error-3/Main.hp new file mode 100644 index 0000000..eacaa7e --- /dev/null +++ b/src/test/fixtures/syntax-error/error-3/Main.hp @@ -0,0 +1,25 @@ +import Syntax; +//Caso teste- Erro de sintaxe 3: +// Nesse caso observa-se que o IR gerado possui a permissao +// para ler(Reads) ou arquivo CCN mesmo estando declarado DENY +// tanto na variavel 'alice', quanto na chamada do main. +// Conclusão: +// Aparentemente a linguagem irá determinar que, sempre após um EXCEPT, +// será considerado o exato Oposto da Sentença anterior (ALLOW/DENY), ou seja: + +// DENY +// EXCEPT -> Tudo abaixo desse EXCEPT será ALLOWed, ate achar outro EXCEPT + +// ALLOW +// EXCEPT -> Tudo abaixo desse EXCEPT será DENY(i)ed, ate achar outro EXCEPT + +main = + DENY + EXCEPT { + ALLOW { + Actors: Analyst + Resources + Actions + } + DENY Syntax::alice + }; \ No newline at end of file diff --git a/src/test/fixtures/syntax-error/error-3/Syntax.hp b/src/test/fixtures/syntax-error/error-3/Syntax.hp new file mode 100644 index 0000000..1876ce0 --- /dev/null +++ b/src/test/fixtures/syntax-error/error-3/Syntax.hp @@ -0,0 +1,21 @@ +export Syntax where + +data Actors = + Looker(Analyst), + Analyst(Alice, Bob), + Intern(Bob, Jeff), + Alice, Bob, Jeff; + +data Actions = Reads, Deletes, Updates; + +data Resources = + Claims(Finance), + Finance(Customers, Companies), + Customers(CCN), Companies(EMAIL, SSN), + CCN, EMAIL, SSN; + +alice = DENY { + Actors: Alice + Resources: CCN + Actions: Reads + }; \ No newline at end of file diff --git a/src/test/fixtures/syntax-error/error-4/Main.hp b/src/test/fixtures/syntax-error/error-4/Main.hp new file mode 100644 index 0000000..a76a04d --- /dev/null +++ b/src/test/fixtures/syntax-error/error-4/Main.hp @@ -0,0 +1,29 @@ +import Syntax; + +// Caso teste- Erro de sintaxe 4: +// A IR gerado não nega o acesso de Bob como +// especificado no 'segundo EXCEPT' + +// Colocando EXCEPT { +// ALLOW {...} +// EXCEPT{...} +// }; +// ... da forma hierarquica como estava, +// ira aparecer um "line 22:4 extraneous input 'EXCEPT' expecting {'}', 'ALLOW'}" +// Por isso as chaves estão fechando em lugares 'diferenciados' nessa politica. + + +main = + DENY + EXCEPT { + ALLOW { + Actors: Analyst + Resources + Actions + }}; + EXCEPT + DENY { + Actors: Bob + Resources: EMAIL + Actions: Deletes, Updates, Reads + }; \ No newline at end of file diff --git a/src/test/fixtures/syntax-error/error-4/Syntax.hp b/src/test/fixtures/syntax-error/error-4/Syntax.hp new file mode 100644 index 0000000..b5eb6a1 --- /dev/null +++ b/src/test/fixtures/syntax-error/error-4/Syntax.hp @@ -0,0 +1,17 @@ +export Syntax where + +//Arquivo utilizado somente para declarações + +data Actors = + Looker(Analyst), + Analyst(Alice, Bob), + Intern(Bob, Jeff), + Alice, Bob, Jeff; + +data Actions = Reads, Deletes, Updates; + +data Resources = + Claims(Finance), + Finance(Customers, Companies), + Customers(CCN), Companies(EMAIL, SSN), + CCN, EMAIL, SSN; diff --git a/src/test/kotlin/VisitorTest.kt b/src/test/kotlin/VisitorTest.kt index 8d4a12d..e932f9b 100644 --- a/src/test/kotlin/VisitorTest.kt +++ b/src/test/kotlin/VisitorTest.kt @@ -36,4 +36,48 @@ class VisitorTest { assertEquals("undefined name: WrongName::bob", exception.message) } + + @Test + @DisplayName("Should return a null pointer Error") // kotlin.KotlinNullPointerException + fun shouldReturnSyntaxError1() { + val file = "src/test/fixtures/syntax-error/error-1/Main.hp" + val priority = listOf("Actors", "Actions", "Resources") + val exception = assertFailsWith { IR.generate(file, priority) } + assertEquals(null, exception.message) + } + + @Test + @DisplayName("Should return a Syntax Error") // Or Should DENY Alice Reads CCN + fun shouldReturnSyntaxError2() { + val file = "src/test/fixtures/syntax-error/error-2/Main.hp" + val priority = listOf("Actors", "Actions", "Resources") + //val exception = assertFailsWith { IR.generate(file, priority) } + //assertEquals("Some syntax error", exception.message) + val ir = (IR.generate(file, priority) as IRNode).ir + val expectedIRString = "{Bob={Updates=[SSN, EMAIL, CCN], Deletes=[SSN, EMAIL, CCN], Reads=[SSN, EMAIL, CCN]}, Alice={Updates=[SSN, EMAIL, CCN], Deletes=[SSN, EMAIL, CCN], Reads=[SSN, EMAIL]}}" + assertThat(ir.toString()).isEqualTo(expectedIRString) + + } + + @Test + @DisplayName("Should DENY Alice Reads CCN") // Or Should return a Syntax Error + fun shouldReturnSyntaxError3() { + val file = "src/test/fixtures/syntax-error/error-3/Main.hp" + val priority = listOf("Actors", "Actions", "Resources") + val ir = (IR.generate(file, priority) as IRNode).ir + val expectedIRString = "{Bob={Updates=[SSN, EMAIL, CCN], Deletes=[SSN, EMAIL, CCN], Reads=[SSN, EMAIL, CCN]}, Alice={Updates=[SSN, EMAIL, CCN], Deletes=[SSN, EMAIL, CCN], Reads=[SSN, EMAIL]}}" + //print(ir.toString()) + assertThat(ir.toString()).isEqualTo(expectedIRString) + + } + + @Test + @DisplayName("Should DENY Bob Actions on EMAIL") + fun shouldReturnSyntaxError4() { + val file = "src/test/fixtures/syntax-error/error-4/Main.hp" + val priority = listOf("Actors", "Actions", "Resources") + val ir = (IR.generate(file, priority) as IRNode).ir + val expectedIRString = "{Bob={Updates=[SSN, CCN], Deletes=[SSN, CCN], Reads=[SSN, CCN]}, Alice={Updates=[SSN, EMAIL, CCN], Deletes=[SSN, EMAIL, CCN], Reads=[SSN, EMAIL, CCN]}}" + assertThat(ir.toString()).isEqualTo(expectedIRString) + } } \ No newline at end of file From 3fe070fd3648bdac680a36182b3e902d7475c7f6 Mon Sep 17 00:00:00 2001 From: CelsoSimoes <48064998+CelsoSimoes@users.noreply.github.com> Date: Wed, 21 Oct 2020 21:38:39 -0300 Subject: [PATCH 2/3] Refactoring the regression tests on syntax errors; Deleting excess comments --- .../syntax-error/deny-expecting-allow/Main.hp | 12 +++++ .../Syntax.hp | 0 .../fixtures/syntax-error/error-1/Main.hp | 16 ------- .../fixtures/syntax-error/error-2/Main.hp | 30 ------------- .../fixtures/syntax-error/error-3/Main.hp | 25 ----------- .../fixtures/syntax-error/error-4/Main.hp | 29 ------------ .../ImportedVariableError.hp} | 2 +- .../syntax-error/imported-variable/Main.hp | 19 ++++++++ .../fixtures/visitor/nested-excepts/Main.hp | 18 ++++++++ .../nested-excepts/NestedExcepts.hp} | 4 +- .../wrong-name/undefined-attribute/Main.hp | 12 +++++ .../UndefinedAttribute.hp} | 4 +- src/test/kotlin/unit/IRVisitorTest.kt | 45 +++++++------------ src/test/kotlin/unit/ParsingTest.kt | 9 ++++ 14 files changed, 91 insertions(+), 134 deletions(-) create mode 100644 src/test/fixtures/syntax-error/deny-expecting-allow/Main.hp rename src/test/fixtures/syntax-error/{error-2 => deny-expecting-allow}/Syntax.hp (100%) delete mode 100644 src/test/fixtures/syntax-error/error-1/Main.hp delete mode 100644 src/test/fixtures/syntax-error/error-2/Main.hp delete mode 100644 src/test/fixtures/syntax-error/error-3/Main.hp delete mode 100644 src/test/fixtures/syntax-error/error-4/Main.hp rename src/test/fixtures/syntax-error/{error-3/Syntax.hp => imported-variable/ImportedVariableError.hp} (91%) create mode 100644 src/test/fixtures/syntax-error/imported-variable/Main.hp create mode 100644 src/test/fixtures/visitor/nested-excepts/Main.hp rename src/test/fixtures/{syntax-error/error-4/Syntax.hp => visitor/nested-excepts/NestedExcepts.hp} (79%) create mode 100644 src/test/fixtures/wrong-name/undefined-attribute/Main.hp rename src/test/fixtures/{syntax-error/error-1/Syntax.hp => wrong-name/undefined-attribute/UndefinedAttribute.hp} (80%) diff --git a/src/test/fixtures/syntax-error/deny-expecting-allow/Main.hp b/src/test/fixtures/syntax-error/deny-expecting-allow/Main.hp new file mode 100644 index 0000000..6cbf471 --- /dev/null +++ b/src/test/fixtures/syntax-error/deny-expecting-allow/Main.hp @@ -0,0 +1,12 @@ +import Syntax; + +main = + DENY + EXCEPT { + ALLOW { + Actors: Analyst + Resources + Actions + } + DENY Syntax::alice + }; \ No newline at end of file diff --git a/src/test/fixtures/syntax-error/error-2/Syntax.hp b/src/test/fixtures/syntax-error/deny-expecting-allow/Syntax.hp similarity index 100% rename from src/test/fixtures/syntax-error/error-2/Syntax.hp rename to src/test/fixtures/syntax-error/deny-expecting-allow/Syntax.hp diff --git a/src/test/fixtures/syntax-error/error-1/Main.hp b/src/test/fixtures/syntax-error/error-1/Main.hp deleted file mode 100644 index 9f83c9a..0000000 --- a/src/test/fixtures/syntax-error/error-1/Main.hp +++ /dev/null @@ -1,16 +0,0 @@ -import Syntax; -// Esse teste PASSA. (Baseado no WrongName) -//Caso teste- Erro de sintaxe 1: -// Deve retornar um erro devido ao nome do Actor dentro da -// variavel jeff estar errado. - -main = - DENY - EXCEPT { - ALLOW { - Actors: Analyst - Resources - Actions - } - ALLOW Syntax::jeff - }; \ No newline at end of file diff --git a/src/test/fixtures/syntax-error/error-2/Main.hp b/src/test/fixtures/syntax-error/error-2/Main.hp deleted file mode 100644 index 29357b9..0000000 --- a/src/test/fixtures/syntax-error/error-2/Main.hp +++ /dev/null @@ -1,30 +0,0 @@ -import Syntax; - -// Caso teste- Erro de sintaxe 2: -// A IR gerado admite que a Actor Alice execute a Action Reads -// no arquivo CCN, mesmo estando declarado DENY na variavel -// 'alice'. -// Isso deveria gerar um erro de Sintaxe ou gerar uma IR que negue -// o acesso por Read de Alice ao CCN. Contudo, somente um aviso está sendo gerado: -// "line 24:4 extraneous input 'DENY' expecting {'}', 'ALLOW'}" -// Em adendo, mesmo se removermos o ALLOW abaixo, antes da variável -// 'Syntax::alice', a linguagem ira interpretar que a query dentro -// da variavel é ALLOWed. - -main = - DENY - EXCEPT { - ALLOW { - Actors: Analyst - Resources - Actions - } - EXCEPT { - DENY { - Actors: Bob - Resources: EMAIL - Actions: Deletes, Updates, Reads - } - } - ALLOW Syntax::alice - }; \ No newline at end of file diff --git a/src/test/fixtures/syntax-error/error-3/Main.hp b/src/test/fixtures/syntax-error/error-3/Main.hp deleted file mode 100644 index eacaa7e..0000000 --- a/src/test/fixtures/syntax-error/error-3/Main.hp +++ /dev/null @@ -1,25 +0,0 @@ -import Syntax; -//Caso teste- Erro de sintaxe 3: -// Nesse caso observa-se que o IR gerado possui a permissao -// para ler(Reads) ou arquivo CCN mesmo estando declarado DENY -// tanto na variavel 'alice', quanto na chamada do main. -// Conclusão: -// Aparentemente a linguagem irá determinar que, sempre após um EXCEPT, -// será considerado o exato Oposto da Sentença anterior (ALLOW/DENY), ou seja: - -// DENY -// EXCEPT -> Tudo abaixo desse EXCEPT será ALLOWed, ate achar outro EXCEPT - -// ALLOW -// EXCEPT -> Tudo abaixo desse EXCEPT será DENY(i)ed, ate achar outro EXCEPT - -main = - DENY - EXCEPT { - ALLOW { - Actors: Analyst - Resources - Actions - } - DENY Syntax::alice - }; \ No newline at end of file diff --git a/src/test/fixtures/syntax-error/error-4/Main.hp b/src/test/fixtures/syntax-error/error-4/Main.hp deleted file mode 100644 index a76a04d..0000000 --- a/src/test/fixtures/syntax-error/error-4/Main.hp +++ /dev/null @@ -1,29 +0,0 @@ -import Syntax; - -// Caso teste- Erro de sintaxe 4: -// A IR gerado não nega o acesso de Bob como -// especificado no 'segundo EXCEPT' - -// Colocando EXCEPT { -// ALLOW {...} -// EXCEPT{...} -// }; -// ... da forma hierarquica como estava, -// ira aparecer um "line 22:4 extraneous input 'EXCEPT' expecting {'}', 'ALLOW'}" -// Por isso as chaves estão fechando em lugares 'diferenciados' nessa politica. - - -main = - DENY - EXCEPT { - ALLOW { - Actors: Analyst - Resources - Actions - }}; - EXCEPT - DENY { - Actors: Bob - Resources: EMAIL - Actions: Deletes, Updates, Reads - }; \ No newline at end of file diff --git a/src/test/fixtures/syntax-error/error-3/Syntax.hp b/src/test/fixtures/syntax-error/imported-variable/ImportedVariableError.hp similarity index 91% rename from src/test/fixtures/syntax-error/error-3/Syntax.hp rename to src/test/fixtures/syntax-error/imported-variable/ImportedVariableError.hp index 1876ce0..c746773 100644 --- a/src/test/fixtures/syntax-error/error-3/Syntax.hp +++ b/src/test/fixtures/syntax-error/imported-variable/ImportedVariableError.hp @@ -1,4 +1,4 @@ -export Syntax where +export ImportedVariableError where data Actors = Looker(Analyst), diff --git a/src/test/fixtures/syntax-error/imported-variable/Main.hp b/src/test/fixtures/syntax-error/imported-variable/Main.hp new file mode 100644 index 0000000..0ea31fe --- /dev/null +++ b/src/test/fixtures/syntax-error/imported-variable/Main.hp @@ -0,0 +1,19 @@ +import ImportedVariableError; + +main = + DENY + EXCEPT { + ALLOW { + Actors: Analyst + Resources + Actions + } + EXCEPT { + DENY { + Actors: Bob + Resources: EMAIL + Actions: Deletes, Updates, Reads + } + } + ALLOW ImportedVariableError::alice + }; \ No newline at end of file diff --git a/src/test/fixtures/visitor/nested-excepts/Main.hp b/src/test/fixtures/visitor/nested-excepts/Main.hp new file mode 100644 index 0000000..7e495ae --- /dev/null +++ b/src/test/fixtures/visitor/nested-excepts/Main.hp @@ -0,0 +1,18 @@ +import NestedExcepts; + +main = + DENY + EXCEPT { + ALLOW { + Actors: Analyst + Resources + Actions + } + EXCEPT { + DENY { + Actors: Bob + Resources: EMAIL + Actions: Deletes, Updates, Reads + } + } + }; \ No newline at end of file diff --git a/src/test/fixtures/syntax-error/error-4/Syntax.hp b/src/test/fixtures/visitor/nested-excepts/NestedExcepts.hp similarity index 79% rename from src/test/fixtures/syntax-error/error-4/Syntax.hp rename to src/test/fixtures/visitor/nested-excepts/NestedExcepts.hp index b5eb6a1..1d550b8 100644 --- a/src/test/fixtures/syntax-error/error-4/Syntax.hp +++ b/src/test/fixtures/visitor/nested-excepts/NestedExcepts.hp @@ -1,6 +1,4 @@ -export Syntax where - -//Arquivo utilizado somente para declarações +export NestedExcepts where data Actors = Looker(Analyst), diff --git a/src/test/fixtures/wrong-name/undefined-attribute/Main.hp b/src/test/fixtures/wrong-name/undefined-attribute/Main.hp new file mode 100644 index 0000000..b58e1e9 --- /dev/null +++ b/src/test/fixtures/wrong-name/undefined-attribute/Main.hp @@ -0,0 +1,12 @@ +import UndefinedAttribute; + +main = + DENY + EXCEPT { + ALLOW { + Actors: Analyst + Resources + Actions + } + ALLOW Syntax::jeff + }; \ No newline at end of file diff --git a/src/test/fixtures/syntax-error/error-1/Syntax.hp b/src/test/fixtures/wrong-name/undefined-attribute/UndefinedAttribute.hp similarity index 80% rename from src/test/fixtures/syntax-error/error-1/Syntax.hp rename to src/test/fixtures/wrong-name/undefined-attribute/UndefinedAttribute.hp index ed14861..59b1add 100644 --- a/src/test/fixtures/syntax-error/error-1/Syntax.hp +++ b/src/test/fixtures/wrong-name/undefined-attribute/UndefinedAttribute.hp @@ -1,4 +1,4 @@ -export Syntax where +export UndefinedAttribute where data Actors = Looker(Analyst), @@ -15,7 +15,7 @@ data Resources = CCN, EMAIL, SSN; jeff = ALLOW { - Actors: Jefa // Nome incorreto + Actors: Jefa // Undefined attribute error Resources: CCN Actions: Reads }; \ No newline at end of file diff --git a/src/test/kotlin/unit/IRVisitorTest.kt b/src/test/kotlin/unit/IRVisitorTest.kt index 6713d59..4f8b0ec 100644 --- a/src/test/kotlin/unit/IRVisitorTest.kt +++ b/src/test/kotlin/unit/IRVisitorTest.kt @@ -37,45 +37,34 @@ class IRVisitorTest { } @Test - @DisplayName("Should return a null pointer Error") // kotlin.KotlinNullPointerException - fun shouldReturnSyntaxError1() { - val file = "src/test/fixtures/syntax-error/error-1/Main.hp" + @DisplayName("Should receive an undefined attribute error") + fun shouldReceiveUndefinedAttributeError() { + val file = "src/test/fixtures/wrong-name/undefined-attribute/Main.hp" val priority = listOf("Actors", "Actions", "Resources") - val exception = assertFailsWith { IR.generate(file, priority) } - assertEquals(null, exception.message) + val exception = assertFailsWith { irFromFile(file, priority) } + assertEquals("undefined attribute: Syntax::jeff::Actors = Jefa", exception.message) } @Test - @DisplayName("Should return a Syntax Error") // Or Should DENY Alice Reads CCN - fun shouldReturnSyntaxError2() { - val file = "src/test/fixtures/syntax-error/error-2/Main.hp" + @DisplayName("Should return a syntax error on imported variable: DENY after an ALLOW") + fun shouldReturnSyntaxErrorImportedVariable() { + val file = "src/test/fixtures/syntax-error/imported-variable/Main.hp" val priority = listOf("Actors", "Actions", "Resources") - //val exception = assertFailsWith { IR.generate(file, priority) } - //assertEquals("Some syntax error", exception.message) - val ir = (IR.generate(file, priority) as IRNode).ir - val expectedIRString = "{Bob={Updates=[SSN, EMAIL, CCN], Deletes=[SSN, EMAIL, CCN], Reads=[SSN, EMAIL, CCN]}, Alice={Updates=[SSN, EMAIL, CCN], Deletes=[SSN, EMAIL, CCN], Reads=[SSN, EMAIL]}}" - assertThat(ir.toString()).isEqualTo(expectedIRString) + + val exception = assertFailsWith { + irFromFile(file, priority) + } - } + assertEquals("line 29:10 syntax error 'DENY' after an 'ALLOW'", exception.message) - @Test - @DisplayName("Should DENY Alice Reads CCN") // Or Should return a Syntax Error - fun shouldReturnSyntaxError3() { - val file = "src/test/fixtures/syntax-error/error-3/Main.hp" - val priority = listOf("Actors", "Actions", "Resources") - val ir = (IR.generate(file, priority) as IRNode).ir - val expectedIRString = "{Bob={Updates=[SSN, EMAIL, CCN], Deletes=[SSN, EMAIL, CCN], Reads=[SSN, EMAIL, CCN]}, Alice={Updates=[SSN, EMAIL, CCN], Deletes=[SSN, EMAIL, CCN], Reads=[SSN, EMAIL]}}" - //print(ir.toString()) - assertThat(ir.toString()).isEqualTo(expectedIRString) - } @Test - @DisplayName("Should DENY Bob Actions on EMAIL") - fun shouldReturnSyntaxError4() { - val file = "src/test/fixtures/syntax-error/error-4/Main.hp" + @DisplayName("Should generate the correct IR even with multiple 'EXCEPT' nested") + fun shouldDenyBobActionsOnEmail() { + val file = "src/test/fixtures/visitor/nested-excepts/Main.hp" val priority = listOf("Actors", "Actions", "Resources") - val ir = (IR.generate(file, priority) as IRNode).ir + val ir = irFromFile(file, priority) val expectedIRString = "{Bob={Updates=[SSN, CCN], Deletes=[SSN, CCN], Reads=[SSN, CCN]}, Alice={Updates=[SSN, EMAIL, CCN], Deletes=[SSN, EMAIL, CCN], Reads=[SSN, EMAIL, CCN]}}" assertThat(ir.toString()).isEqualTo(expectedIRString) } diff --git a/src/test/kotlin/unit/ParsingTest.kt b/src/test/kotlin/unit/ParsingTest.kt index b3a7791..25712e7 100644 --- a/src/test/kotlin/unit/ParsingTest.kt +++ b/src/test/kotlin/unit/ParsingTest.kt @@ -55,4 +55,13 @@ class ParsingTest { val error = "line 6:10 mismatched input 'INVALID' expecting 'ALLOW'" assertFailsWith(error) { parse(tokenize(program)) } } + + @Test + @DisplayName("Should return 'mismatched input' on syntax error: input 'DENY' expecting 'ALLOW' or 'EXCEPT'") + fun shouldReturnSyntaxErrorDenyExpectingAllow() { + val file = "src/test/fixtures/syntax-error/deny-expecting-allow/Main.hp" + val error = "line 24:4 mismatched input 'DENY' expecting 'ALLOW'" + assertFailsWith(error) { parse(tokenize(file)) } + + } } \ No newline at end of file From 897f1e14060355e1a9e9526e12063e09bd9d023c Mon Sep 17 00:00:00 2001 From: CelsoSimoes <48064998+CelsoSimoes@users.noreply.github.com> Date: Fri, 30 Oct 2020 15:00:10 -0300 Subject: [PATCH 3/3] fix: syntax errors --- src/test/kotlin/unit/IRVisitorTest.kt | 2 ++ src/test/kotlin/unit/ParsingTest.kt | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/test/kotlin/unit/IRVisitorTest.kt b/src/test/kotlin/unit/IRVisitorTest.kt index a72a2bb..ec10ae2 100644 --- a/src/test/kotlin/unit/IRVisitorTest.kt +++ b/src/test/kotlin/unit/IRVisitorTest.kt @@ -117,8 +117,10 @@ class IRVisitorTest { fun shouldDenyBobActionsOnEmail() { val file = "src/test/fixtures/visitor/nested-excepts/Main.hp" val priority = listOf("Actors", "Actions", "Resources") + val castelo = "teste" val ir = irFromFile(file, priority) val expectedIRString = "{Bob={Updates=[SSN, CCN], Deletes=[SSN, CCN], Reads=[SSN, CCN]}, Alice={Updates=[SSN, EMAIL, CCN], Deletes=[SSN, EMAIL, CCN], Reads=[SSN, EMAIL, CCN]}}" assertThat(ir.toString()).isEqualTo(expectedIRString) } + } } \ No newline at end of file diff --git a/src/test/kotlin/unit/ParsingTest.kt b/src/test/kotlin/unit/ParsingTest.kt index b197b58..f55a2e1 100644 --- a/src/test/kotlin/unit/ParsingTest.kt +++ b/src/test/kotlin/unit/ParsingTest.kt @@ -39,7 +39,7 @@ class ParsingTest { } @Test - @DisplayName("Should throw ParseCancellationException on syntax rrror") + @DisplayName("Should throw ParseCancellationException on syntax error") fun shouldThrowParseCancellationExceptionOnSyntaxError(){ val program = """ @@ -62,7 +62,8 @@ class ParsingTest { val file = "src/test/fixtures/syntax-error/deny-expecting-allow/Main.hp" val error = "line 24:4 mismatched input 'DENY' expecting 'ALLOW'" assertFailsWith(error) { parse(tokenize(file)) } - + } + @Test @DisplayName("Should parse valid attribute expressions") fun shouldParseValidAttributeExpression(){