Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding new syntax tests #1

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/test/fixtures/syntax-error/error-1/Main.hp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import Syntax;
// Esse teste PASSA. (Baseado no WrongName)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the comments

//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
};
21 changes: 21 additions & 0 deletions src/test/fixtures/syntax-error/error-1/Syntax.hp
Original file line number Diff line number Diff line change
@@ -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
};
30 changes: 30 additions & 0 deletions src/test/fixtures/syntax-error/error-2/Main.hp
Original file line number Diff line number Diff line change
@@ -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
};
21 changes: 21 additions & 0 deletions src/test/fixtures/syntax-error/error-2/Syntax.hp
Original file line number Diff line number Diff line change
@@ -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
};
25 changes: 25 additions & 0 deletions src/test/fixtures/syntax-error/error-3/Main.hp
Original file line number Diff line number Diff line change
@@ -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
};
21 changes: 21 additions & 0 deletions src/test/fixtures/syntax-error/error-3/Syntax.hp
Original file line number Diff line number Diff line change
@@ -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
};
29 changes: 29 additions & 0 deletions src/test/fixtures/syntax-error/error-4/Main.hp
Original file line number Diff line number Diff line change
@@ -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
};
17 changes: 17 additions & 0 deletions src/test/fixtures/syntax-error/error-4/Syntax.hp
Original file line number Diff line number Diff line change
@@ -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;
44 changes: 44 additions & 0 deletions src/test/kotlin/VisitorTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,48 @@ class VisitorTest {
assertEquals("undefined name: WrongName::bob", exception.message)

}

@Test
@DisplayName("Should return a null pointer Error") // kotlin.KotlinNullPointerException
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Give it a more descriptive name. What is this test case testing?

fun shouldReturnSyntaxError1() {
val file = "src/test/fixtures/syntax-error/error-1/Main.hp"
val priority = listOf("Actors", "Actions", "Resources")
val exception = assertFailsWith<Exception> { IR.generate(file, priority) }
assertEquals(null, exception.message)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Errors should be handled with a descriptive message instead of a not cool KotlinNullPointerException. What would be a good message that make explicit the error that is occurring?

}

@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<Exception> { IR.generate(file, priority) }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove comments

//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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this testing a syntax error? which one?

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)
}
}