Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ package viaduct.engine.api

interface CheckerExecutorFactory {
fun checkerExecutorForField(
schema: ViaductSchema,
typeName: String,
fieldName: String
): CheckerExecutor?

fun checkerExecutorForType(typeName: String): CheckerExecutor?
fun checkerExecutorForType(
schema: ViaductSchema,
typeName: String
): CheckerExecutor?
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ class NoOpCheckerExecutorFactoryImpl
@Inject
constructor() : CheckerExecutorFactory {
override fun checkerExecutorForField(
schema: ViaductSchema,
typeName: String,
fieldName: String
): CheckerExecutor? = null

override fun checkerExecutorForType(typeName: String): CheckerExecutor? = null
override fun checkerExecutorForType(
schema: ViaductSchema,
typeName: String
): CheckerExecutor? = null
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@ package viaduct.engine.api

import kotlin.test.assertNull
import org.junit.jupiter.api.Test
import viaduct.engine.api.mocks.MockSchema

internal class NoOpCheckerExecutorFactoryImplTest {
private val testSubject = NoOpCheckerExecutorFactoryImpl()
private val mockSchema = MockSchema.mk("type AnyType { anyField: String }")

@Test
fun `Test no op functionality`() {
val provider = testSubject.checkerExecutorForField("anyType", "anyField")
val provider = testSubject.checkerExecutorForField(mockSchema, "anyType", "anyField")
assertNull(provider)
}

@Test
fun `Test no op on node`() {
val provider = testSubject.checkerExecutorForType("anyType")
val provider = testSubject.checkerExecutorForType(mockSchema, "anyType")
assertNull(provider)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,18 @@ class MocksAdditionalTest {
fun `MockCheckerExecutorFactory functionality`() {
val fieldChecker = MockCheckerExecutor()
val typeChecker = MockCheckerExecutor()
val mockSchema = MockSchema.mk("type TestType { testField: String } type TestNode implements Node { id: ID! }")

val factory = MockCheckerExecutorFactory(
mapOf(Pair("TestType", "testField") to fieldChecker),
mapOf("TestNode" to typeChecker)
)

assertSame(fieldChecker, factory.checkerExecutorForField("TestType", "testField"))
assertNull(factory.checkerExecutorForField("TestType", "nonExistent"))
assertSame(fieldChecker, factory.checkerExecutorForField(mockSchema, "TestType", "testField"))
assertNull(factory.checkerExecutorForField(mockSchema, "TestType", "nonExistent"))

assertSame(typeChecker, factory.checkerExecutorForType("TestNode"))
assertNull(factory.checkerExecutorForType("NonExistent"))
assertSame(typeChecker, factory.checkerExecutorForType(mockSchema, "TestNode"))
assertNull(factory.checkerExecutorForType(mockSchema, "NonExistent"))
}

@Test
Expand Down Expand Up @@ -319,8 +320,9 @@ class MocksAdditionalTest {

@Test
fun `MockCheckerExecutorFactory with null inputs`() {
val mockSchema = MockSchema.mk("type AnyType { anyField: String }")
val factory = MockCheckerExecutorFactory()
assertNull(factory.checkerExecutorForField("AnyType", "anyField"))
assertNull(factory.checkerExecutorForType("AnyType"))
assertNull(factory.checkerExecutorForField(mockSchema, "AnyType", "anyField"))
assertNull(factory.checkerExecutorForType(mockSchema, "AnyType"))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -420,13 +420,17 @@ class MockCheckerExecutorFactory(
val typeCheckerExecutors: Map<String, CheckerExecutor>? = null
) : CheckerExecutorFactory {
override fun checkerExecutorForField(
schema: ViaductSchema,
typeName: String,
fieldName: String
): CheckerExecutor? {
return checkerExecutors?.get(Pair(typeName, fieldName))
}

override fun checkerExecutorForType(typeName: String): CheckerExecutor? {
override fun checkerExecutorForType(
schema: ViaductSchema,
typeName: String
): CheckerExecutor? {
return typeCheckerExecutors?.get(typeName)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class DispatcherRegistryFactory(
fieldResolverDispatchers[fieldCoord] = FieldResolverDispatcherImpl(executor)
fieldResolverExecutorsToValidate[fieldCoord] = executor
// Enable access controls for resolver fields only
checkerExecutorFactory.checkerExecutorForField(fieldCoord.first, fieldCoord.second)?.let {
checkerExecutorFactory.checkerExecutorForField(schema, fieldCoord.first, fieldCoord.second)?.let {
fieldCheckerDispatchers[fieldCoord] = CheckerDispatcherImpl(it)
fieldCheckerExecutorsToValidate[fieldCoord] = it
}
Expand All @@ -78,7 +78,7 @@ class DispatcherRegistryFactory(
}
for ((typeName, _) in nodeResolverDispatchers) {
// Enable access controls for node resolvers only
checkerExecutorFactory.checkerExecutorForType(typeName)?.let {
checkerExecutorFactory.checkerExecutorForType(schema, typeName)?.let {
typeCheckerDispatchers[typeName] = CheckerDispatcherImpl(it)
typeCheckerExecutorsToValidate[typeName] = it
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class PolicyCheckFeatureAppTest : FeatureAppTestBase() {
private val graphQLSchema = schema.schema

override fun checkerExecutorForField(
schema: ViaductSchema,
typeName: String,
fieldName: String
): CheckerExecutor? {
Expand All @@ -111,7 +112,10 @@ class PolicyCheckFeatureAppTest : FeatureAppTestBase() {
)
}

override fun checkerExecutorForType(typeName: String): CheckerExecutor? {
override fun checkerExecutorForType(
schema: ViaductSchema,
typeName: String
): CheckerExecutor? {
println("DEBUG: checkerExecutorForType called for type: $typeName")
val graphqlType = graphQLSchema.getObjectType(typeName)
?: throw IllegalStateException("Cannot find type $typeName")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import viaduct.engine.api.Coordinate
import viaduct.engine.api.EngineObjectData
import viaduct.engine.api.RequiredSelectionSet
import viaduct.engine.api.SelectionSetVariable
import viaduct.engine.api.ViaductSchema
import viaduct.engine.api.select.SelectionsParser
import viaduct.service.api.spi.Flags
import viaduct.service.api.spi.mocks.MockFlagManager
Expand Down Expand Up @@ -388,11 +389,15 @@ class FeatureTestBuilder {
.withCheckerExecutorFactory(
object : CheckerExecutorFactory {
override fun checkerExecutorForField(
schema: ViaductSchema,
typeName: String,
fieldName: String
): CheckerExecutor? = fieldCheckerStubs[typeName to fieldName]

override fun checkerExecutorForType(typeName: String): CheckerExecutor? = typeCheckerStubs[typeName]
override fun checkerExecutorForType(
schema: ViaductSchema,
typeName: String
): CheckerExecutor? = typeCheckerStubs[typeName]
}
)

Expand Down