Skip to content

Commit

Permalink
fix: quad filter
Browse files Browse the repository at this point in the history
  • Loading branch information
blake-regalia committed Dec 5, 2024
1 parent 148c9a2 commit 04c995f
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 11 deletions.
8 changes: 6 additions & 2 deletions src/main/kotlin/org/openmbee/flexo/mms/GuardedPatch.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ import org.openmbee.flexo.mms.server.SparqlUpdateRequest

fun quadDataFilter(subjectIri: String): (Quad)->Boolean {
return {
it.subject.isURI && it.subject.uri == subjectIri && !it.predicate.uri.contains(FORBIDDEN_PREDICATES_REGEX)
if(it.subject.isURI && it.subject.uri == subjectIri && it.predicate.uri.contains(FORBIDDEN_PREDICATES_REGEX)) {
throw Http400Exception("User not allowed to use IRIs in the namespace <${it.predicate.uri}>")
}

true
}
}

Expand All @@ -25,7 +29,7 @@ fun quadPatternFilter(subjectIri: String): (Quad)->Boolean {
throw VariablesNotAllowedInUpdateException("subject")
}
else if(!it.subject.isURI || it.subject.uri != subjectIri) {
throw Http400Exception("All subjects must be exactly <${subjectIri}>. Refusing to evalute ${it.subject}")
throw Http400Exception("All subjects must be exactly <${subjectIri}>. Refusing to evaluate ${it.subject}")
}
else if(it.predicate.isVariable) {
throw VariablesNotAllowedInUpdateException("predicate")
Expand Down
76 changes: 67 additions & 9 deletions src/test/kotlin/org/openmbee/flexo/mms/util/LinkedDataPlatform.kt
Original file line number Diff line number Diff line change
Expand Up @@ -495,26 +495,24 @@ class LinkedDataPlatformDirectContainerTests(
}
}

"PATCH $resourcePath - SPARQL UPDATE: patch branch with bad delete" {
"PATCH $resourcePath - SPARQL UPDATE: patch branch with bad delete data" {
val createdBase = resourceCreator() // This creates a tuple
withTest {
httpPatch(resourcePath) {
setSparqlUpdateBody(
withAllTestPrefixes(
"""
delete data {
<> mms:id <urn:mms:foo> .
}
""".trimIndent()
)
withAllTestPrefixes("""
delete data {
<> mms:id <urn:mms:foo> .
}
""".trimIndent())
)
}.apply {
response shouldHaveStatus HttpStatusCode.BadRequest
}
}
}

"PATCH $resourcePath - SPARQL UPDATE: patch branch with bad insert" {
"PATCH $resourcePath - SPARQL UPDATE: patch branch with bad insert data" {
val createdBase = resourceCreator()
withTest {
httpPatch(resourcePath) {
Expand All @@ -528,6 +526,66 @@ class LinkedDataPlatformDirectContainerTests(
}
}
}

"PATCH $resourcePath - SPARQL UPDATE: patch branch with bad delete pattern" {
val createdBase = resourceCreator() // This creates a tuple
withTest {
httpPatch(resourcePath) {
setSparqlUpdateBody(
withAllTestPrefixes("""
delete {
<> mms:id <urn:mms:foo> .
}
where {
?s ?p ?o .
}
""".trimIndent())
)
}.apply {
response shouldHaveStatus HttpStatusCode.BadRequest
}
}
}

"PATCH $resourcePath - SPARQL UPDATE: patch branch with bad insert pattern" {
val createdBase = resourceCreator() // This creates a tuple
withTest {
httpPatch(resourcePath) {
setSparqlUpdateBody(
withAllTestPrefixes("""
insert {
<> mms:id <urn:mms:foo> .
}
where {
?s ?p ?o .
}
""".trimIndent())
)
}.apply {
response shouldHaveStatus HttpStatusCode.BadRequest
}
}
}

"PATCH $resourcePath - SPARQL UPDATE: patch branch with bad delete predicate variable" {
val createdBase = resourceCreator() // This creates a tuple
withTest {
httpPatch(resourcePath) {
setSparqlUpdateBody(
withAllTestPrefixes("""
delete {
<> ?p <urn:mms:foo> .
}
where {
?s ?p ?o .
}
""".trimIndent())
)
}.apply {
response shouldHaveStatus HttpStatusCode.BadRequest
}
}
}
}


Expand Down

0 comments on commit 04c995f

Please sign in to comment.