Search in sources :

Example 6 with MockPropertyValue

use of org.apache.nifi.util.MockPropertyValue in project nifi by apache.

the class TestRangerNiFiAuthorizer method testIntegration.

@Test
@Ignore
public void testIntegration() {
    final AuthorizerInitializationContext initializationContext = Mockito.mock(AuthorizerInitializationContext.class);
    final AuthorizerConfigurationContext configurationContext = Mockito.mock(AuthorizerConfigurationContext.class);
    when(configurationContext.getProperty(eq(RangerNiFiAuthorizer.RANGER_SECURITY_PATH_PROP))).thenReturn(new MockPropertyValue("src/test/resources/ranger/ranger-nifi-security.xml"));
    when(configurationContext.getProperty(eq(RangerNiFiAuthorizer.RANGER_AUDIT_PATH_PROP))).thenReturn(new MockPropertyValue("src/test/resources/ranger/ranger-nifi-audit.xml"));
    Authorizer authorizer = new RangerNiFiAuthorizer();
    try {
        authorizer.initialize(initializationContext);
        authorizer.onConfigured(configurationContext);
        final AuthorizationRequest request = new AuthorizationRequest.Builder().resource(new Resource() {

            @Override
            public String getIdentifier() {
                return "/system";
            }

            @Override
            public String getName() {
                return "/system";
            }

            @Override
            public String getSafeDescription() {
                return "system";
            }
        }).action(RequestAction.WRITE).identity("admin").resourceContext(new HashMap<>()).accessAttempt(true).anonymous(false).build();
        final AuthorizationResult result = authorizer.authorize(request);
        Assert.assertEquals(AuthorizationResult.denied().getResult(), result.getResult());
    } finally {
        authorizer.preDestruction();
    }
}
Also used : AuthorizationRequest(org.apache.nifi.authorization.AuthorizationRequest) HashMap(java.util.HashMap) Authorizer(org.apache.nifi.authorization.Authorizer) Resource(org.apache.nifi.authorization.Resource) MockPropertyValue(org.apache.nifi.util.MockPropertyValue) AuthorizerInitializationContext(org.apache.nifi.authorization.AuthorizerInitializationContext) AuthorizationResult(org.apache.nifi.authorization.AuthorizationResult) AuthorizerConfigurationContext(org.apache.nifi.authorization.AuthorizerConfigurationContext) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 7 with MockPropertyValue

use of org.apache.nifi.util.MockPropertyValue in project nifi by apache.

the class TestSchemaNamePropertyStrategy method testNameAndVersion.

@Test
public void testNameAndVersion() throws SchemaNotFoundException, IOException {
    final PropertyValue nameValue = new MockPropertyValue("person");
    final PropertyValue branchValue = new MockPropertyValue(null);
    final PropertyValue versionValue = new MockPropertyValue("1");
    final SchemaNamePropertyStrategy schemaNamePropertyStrategy = new SchemaNamePropertyStrategy(schemaRegistry, nameValue, branchValue, versionValue);
    final SchemaIdentifier expectedSchemaIdentifier = SchemaIdentifier.builder().name(nameValue.getValue()).version(versionValue.asInteger()).build();
    when(schemaRegistry.retrieveSchema(argThat(new SchemaIdentifierMatcher(expectedSchemaIdentifier)))).thenReturn(recordSchema);
    final RecordSchema retrievedSchema = schemaNamePropertyStrategy.getSchema(Collections.emptyMap(), null, recordSchema);
    assertNotNull(retrievedSchema);
}
Also used : MockPropertyValue(org.apache.nifi.util.MockPropertyValue) PropertyValue(org.apache.nifi.components.PropertyValue) MockPropertyValue(org.apache.nifi.util.MockPropertyValue) SchemaIdentifier(org.apache.nifi.serialization.record.SchemaIdentifier) RecordSchema(org.apache.nifi.serialization.record.RecordSchema) Test(org.junit.Test)

Example 8 with MockPropertyValue

use of org.apache.nifi.util.MockPropertyValue in project nifi by apache.

the class TestSchemaNamePropertyStrategy method testNameAndBranch.

@Test
public void testNameAndBranch() throws SchemaNotFoundException, IOException {
    final PropertyValue nameValue = new MockPropertyValue("person");
    final PropertyValue branchValue = new MockPropertyValue("test");
    final PropertyValue versionValue = new MockPropertyValue(null);
    final SchemaNamePropertyStrategy schemaNamePropertyStrategy = new SchemaNamePropertyStrategy(schemaRegistry, nameValue, branchValue, versionValue);
    final SchemaIdentifier expectedSchemaIdentifier = SchemaIdentifier.builder().name(nameValue.getValue()).branch(branchValue.getValue()).build();
    when(schemaRegistry.retrieveSchema(argThat(new SchemaIdentifierMatcher(expectedSchemaIdentifier)))).thenReturn(recordSchema);
    final RecordSchema retrievedSchema = schemaNamePropertyStrategy.getSchema(Collections.emptyMap(), null, recordSchema);
    assertNotNull(retrievedSchema);
}
Also used : MockPropertyValue(org.apache.nifi.util.MockPropertyValue) PropertyValue(org.apache.nifi.components.PropertyValue) MockPropertyValue(org.apache.nifi.util.MockPropertyValue) SchemaIdentifier(org.apache.nifi.serialization.record.SchemaIdentifier) RecordSchema(org.apache.nifi.serialization.record.RecordSchema) Test(org.junit.Test)

Example 9 with MockPropertyValue

use of org.apache.nifi.util.MockPropertyValue in project nifi by apache.

the class TestSchemaNamePropertyStrategy method testNameOnly.

@Test
public void testNameOnly() throws SchemaNotFoundException, IOException {
    final PropertyValue nameValue = new MockPropertyValue("person");
    final PropertyValue branchValue = new MockPropertyValue(null);
    final PropertyValue versionValue = new MockPropertyValue(null);
    final SchemaNamePropertyStrategy schemaNamePropertyStrategy = new SchemaNamePropertyStrategy(schemaRegistry, nameValue, branchValue, versionValue);
    final SchemaIdentifier expectedSchemaIdentifier = SchemaIdentifier.builder().name(nameValue.getValue()).build();
    when(schemaRegistry.retrieveSchema(argThat(new SchemaIdentifierMatcher(expectedSchemaIdentifier)))).thenReturn(recordSchema);
    final RecordSchema retrievedSchema = schemaNamePropertyStrategy.getSchema(Collections.emptyMap(), null, recordSchema);
    assertNotNull(retrievedSchema);
}
Also used : MockPropertyValue(org.apache.nifi.util.MockPropertyValue) PropertyValue(org.apache.nifi.components.PropertyValue) MockPropertyValue(org.apache.nifi.util.MockPropertyValue) SchemaIdentifier(org.apache.nifi.serialization.record.SchemaIdentifier) RecordSchema(org.apache.nifi.serialization.record.RecordSchema) Test(org.junit.Test)

Example 10 with MockPropertyValue

use of org.apache.nifi.util.MockPropertyValue in project nifi by apache.

the class TestSchemaNamePropertyStrategy method testNameAndBlankBranch.

@Test
public void testNameAndBlankBranch() throws SchemaNotFoundException, IOException {
    final PropertyValue nameValue = new MockPropertyValue("person");
    final PropertyValue branchValue = new MockPropertyValue("  ");
    final PropertyValue versionValue = new MockPropertyValue(null);
    final SchemaNamePropertyStrategy schemaNamePropertyStrategy = new SchemaNamePropertyStrategy(schemaRegistry, nameValue, branchValue, versionValue);
    final SchemaIdentifier expectedSchemaIdentifier = SchemaIdentifier.builder().name(nameValue.getValue()).build();
    when(schemaRegistry.retrieveSchema(argThat(new SchemaIdentifierMatcher(expectedSchemaIdentifier)))).thenReturn(recordSchema);
    final RecordSchema retrievedSchema = schemaNamePropertyStrategy.getSchema(Collections.emptyMap(), null, recordSchema);
    assertNotNull(retrievedSchema);
}
Also used : MockPropertyValue(org.apache.nifi.util.MockPropertyValue) PropertyValue(org.apache.nifi.components.PropertyValue) MockPropertyValue(org.apache.nifi.util.MockPropertyValue) SchemaIdentifier(org.apache.nifi.serialization.record.SchemaIdentifier) RecordSchema(org.apache.nifi.serialization.record.RecordSchema) Test(org.junit.Test)

Aggregations

MockPropertyValue (org.apache.nifi.util.MockPropertyValue)23 Test (org.junit.Test)14 PropertyValue (org.apache.nifi.components.PropertyValue)10 HashMap (java.util.HashMap)5 ComponentLog (org.apache.nifi.logging.ComponentLog)5 RecordSchema (org.apache.nifi.serialization.record.RecordSchema)5 MockStateManager (org.apache.nifi.state.MockStateManager)5 AuthorizerCreationException (org.apache.nifi.authorization.exception.AuthorizerCreationException)4 PropertyDescriptor (org.apache.nifi.components.PropertyDescriptor)4 SchemaIdentifier (org.apache.nifi.serialization.record.SchemaIdentifier)4 NiFiProperties (org.apache.nifi.util.NiFiProperties)4 InvocationOnMock (org.mockito.invocation.InvocationOnMock)4 ArrayList (java.util.ArrayList)3 AuthorizerConfigurationContext (org.apache.nifi.authorization.AuthorizerConfigurationContext)3 ConfigurationContext (org.apache.nifi.controller.ConfigurationContext)3 EventAccess (org.apache.nifi.reporting.EventAccess)3 ReportingContext (org.apache.nifi.reporting.ReportingContext)3 ReportingInitializationContext (org.apache.nifi.reporting.ReportingInitializationContext)3 StandardPropertyValue (org.apache.nifi.attribute.expression.language.StandardPropertyValue)2 AuthorizationRequest (org.apache.nifi.authorization.AuthorizationRequest)2