-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
e8a63c1
7bf356d
3fe070f
a15a9c2
897f1e1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
}; |
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 | ||
}; |
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 | ||
}; |
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 | ||
}; |
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 | ||
}; |
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 | ||
}; |
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 | ||
}; |
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; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,4 +36,48 @@ class VisitorTest { | |
assertEquals("undefined name: WrongName::bob", exception.message) | ||
|
||
} | ||
|
||
@Test | ||
@DisplayName("Should return a null pointer Error") // kotlin.KotlinNullPointerException | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
} | ||
|
||
@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) } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove the comments