use of com.palantir.conjure.spec.ConjureDefinition in project conjure by palantir.
the class ConjureSourceFileValidatorTest method testSafetyOnPrimitive.
@Test
public void testSafetyOnPrimitive() {
ConjureDefinition conjureDef = ConjureDefinition.builder().version(1).types(TypeDefinition.object(ObjectDefinition.builder().typeName(FOO).fields(FieldDefinition.builder().fieldName(FieldName.of("bad")).type(Type.primitive(PrimitiveType.STRING)).safety(LogSafety.UNSAFE).docs(DOCS).build()).build())).build();
ConjureDefinitionValidator.validateAll(conjureDef, SafetyDeclarationRequirements.REQUIRED);
}
use of com.palantir.conjure.spec.ConjureDefinition in project conjure by palantir.
the class ConjureSourceFileValidatorTest method testSafetyOnMap.
@Test
public void testSafetyOnMap() {
ConjureDefinition conjureDef = ConjureDefinition.builder().version(1).types(TypeDefinition.object(ObjectDefinition.builder().typeName(FOO).fields(FieldDefinition.builder().fieldName(FieldName.of("bad")).type(Type.map(MapType.of(Type.primitive(PrimitiveType.STRING), Type.primitive(PrimitiveType.STRING)))).safety(LogSafety.DO_NOT_LOG).docs(DOCS).build()).build())).build();
assertThatThrownBy(() -> ConjureDefinitionValidator.validateAll(conjureDef, SafetyDeclarationRequirements.ALLOWED)).isInstanceOf(IllegalStateException.class).hasMessageContainingAll("Maps cannot declare log safety", "Consider using alias types");
}
use of com.palantir.conjure.spec.ConjureDefinition in project conjure by palantir.
the class ConjureSourceFileValidatorTest method testNoIllegalMapKeys_intermediateAlias.
@Test
public void testNoIllegalMapKeys_intermediateAlias() {
ConjureDefinition conjureDef = ConjureDefinition.builder().version(1).types(TypeDefinition.alias(AliasDefinition.builder().typeName(TypeName.of("AliasName", "package")).alias(Type.list(ListType.of(Type.primitive(PrimitiveType.STRING)))).build())).types(TypeDefinition.object(ObjectDefinition.builder().typeName(FOO).fields(FieldDefinition.builder().fieldName(FieldName.of("bad")).type(Type.map(MapType.of(Type.list(ListType.of(Type.primitive(PrimitiveType.STRING))), Type.primitive(PrimitiveType.STRING)))).docs(DOCS).build()).build())).build();
assertThatThrownBy(() -> ConjureDefinitionValidator.ILLEGAL_MAP_KEYS.validate(conjureDef)).isInstanceOf(IllegalStateException.class).hasMessageStartingWith("Illegal map key found in object Foo");
}
use of com.palantir.conjure.spec.ConjureDefinition in project conjure by palantir.
the class ConjureSourceFileValidatorTest method testInvalidSafetyArgument_bearertoken.
@Test
public void testInvalidSafetyArgument_bearertoken() {
ConjureDefinition conjureDef = ConjureDefinition.builder().version(1).services(ServiceDefinition.builder().serviceName(TypeName.of("Service", "com.palantir.product")).endpoints(EndpointDefinition.builder().endpointName(EndpointName.of("end")).httpMethod(HttpMethod.PUT).httpPath(HttpPath.of("/path")).args(ArgumentDefinition.builder().argName(ArgumentName.of("arg")).type(Type.primitive(PrimitiveType.BEARERTOKEN)).paramType(ParameterType.body(BodyParameterType.of())).safety(LogSafety.UNSAFE).build()).build()).build()).build();
assertThatThrownBy(() -> ConjureDefinitionValidator.validateAll(conjureDef, SafetyDeclarationRequirements.ALLOWED)).isInstanceOf(IllegalStateException.class).hasMessageContaining("Service.end(arg): bearertoken values are do-not-log by default and cannot be configured");
}
use of com.palantir.conjure.spec.ConjureDefinition in project conjure by palantir.
the class ConjureSourceFileValidatorTest method testValidArgumentSafety.
@Test
public void testValidArgumentSafety() {
ConjureDefinition conjureDef = ConjureDefinition.builder().version(1).services(ServiceDefinition.builder().serviceName(TypeName.of("Service", "com.palantir.product")).endpoints(EndpointDefinition.builder().endpointName(EndpointName.of("end")).httpMethod(HttpMethod.PUT).httpPath(HttpPath.of("/path")).args(ArgumentDefinition.builder().argName(ArgumentName.of("arg")).type(Type.primitive(PrimitiveType.STRING)).paramType(ParameterType.body(BodyParameterType.of())).safety(LogSafety.UNSAFE).build()).build()).build()).build();
ConjureDefinitionValidator.validateAll(conjureDef, SafetyDeclarationRequirements.REQUIRED);
}
Aggregations