Search in sources :

Example 1 with Authentication

use of io.crate.auth.Authentication in project crate by crate.

the class PostgresWireProtocolTest method testPasswordMessageAuthenticationProcess.

@Test
public void testPasswordMessageAuthenticationProcess() throws Exception {
    PostgresWireProtocol ctx = new PostgresWireProtocol(mock(SQLOperations.class), sessionContext -> AccessControl.DISABLED, new Authentication() {

        @Override
        public AuthenticationMethod resolveAuthenticationType(String user, ConnectionProperties connectionProperties) {
            return new AuthenticationMethod() {

                @Nullable
                @Override
                public User authenticate(String userName, @Nullable SecureString passwd, ConnectionProperties connProperties) {
                    return null;
                }

                @Override
                public String name() {
                    return "password";
                }
            };
        }
    }, null);
    channel = new EmbeddedChannel(ctx.decoder, ctx.handler);
    ByteBuf respBuf;
    ByteBuf buffer = Unpooled.buffer();
    ClientMessages.sendStartupMessage(buffer, "doc");
    channel.writeInbound(buffer);
    respBuf = channel.readOutbound();
    try {
        // AuthenticationCleartextPassword
        assertThat((char) respBuf.readByte(), is('R'));
    } finally {
        respBuf.release();
    }
    buffer = Unpooled.buffer();
    ClientMessages.sendPasswordMessage(buffer, "pw");
    channel.writeInbound(buffer);
    respBuf = channel.readOutbound();
    try {
        // Auth OK
        assertThat((char) respBuf.readByte(), is('R'));
    } finally {
        respBuf.release();
    }
}
Also used : User(io.crate.user.User) Authentication(io.crate.auth.Authentication) AlwaysOKAuthentication(io.crate.auth.AlwaysOKAuthentication) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) SecureString(org.elasticsearch.common.settings.SecureString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) AuthenticationMethod(io.crate.auth.AuthenticationMethod) ByteBuf(io.netty.buffer.ByteBuf) SQLOperations(io.crate.action.sql.SQLOperations) Nullable(javax.annotation.Nullable) SecureString(org.elasticsearch.common.settings.SecureString) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Aggregations

SQLOperations (io.crate.action.sql.SQLOperations)1 AlwaysOKAuthentication (io.crate.auth.AlwaysOKAuthentication)1 Authentication (io.crate.auth.Authentication)1 AuthenticationMethod (io.crate.auth.AuthenticationMethod)1 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)1 User (io.crate.user.User)1 ByteBuf (io.netty.buffer.ByteBuf)1 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)1 Nullable (javax.annotation.Nullable)1 SecureString (org.elasticsearch.common.settings.SecureString)1 Test (org.junit.Test)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1