Skip to content

Commit 8a638a2

Browse files
committed
#940 Fix NPE on auth failure
1 parent 9e6afbe commit 8a638a2

3 files changed

Lines changed: 56 additions & 8 deletions

File tree

src/docs/asciidoc/release_notes.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ See also <<compat-legacy-auth>>.
4949
* Fixed: Off-by-one error in default value for `maxInlineBlobSize` (https://github.com/FirebirdSQL/jaybird/issues/937[#937])
5050
+
5151
Fix was contributed by Artyom Abakumov.
52+
* Fixed: `NullPointerException` on authentication failure with non-existent user and single plugin in `AuthServer` (https://github.com/FirebirdSQL/jaybird/issues/940[#940])
5253

5354
=== Jaybird 6.0.5
5455

src/main/org/firebirdsql/gds/ng/wire/WireConnection.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import java.util.ArrayList;
5555
import java.util.Arrays;
5656
import java.util.Collections;
57+
import java.util.Comparator;
5758
import java.util.HashMap;
5859
import java.util.List;
5960
import java.util.Map;
@@ -600,8 +601,9 @@ void clearServerKeys() {
600601
}
601602

602603
private AbstractWireOperations getDefaultWireOperations() {
603-
ProtocolDescriptor protocolDescriptor = protocols
604-
.getProtocolDescriptor(WireProtocolConstants.PROTOCOL_VERSION10);
604+
// Use minimum available protocol version (previously we always used version 10)
605+
ProtocolDescriptor protocolDescriptor = protocols.stream()
606+
.min(Comparator.comparingInt(ProtocolDescriptor::getVersion)).orElseThrow();
605607
return (AbstractWireOperations) protocolDescriptor.createWireOperations(this, NOOP_WARNING_MESSAGE_CALLBACK);
606608
}
607609

src/test/org/firebirdsql/jdbc/FBDriverTest.java

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@
2626
import org.firebirdsql.gds.JaybirdErrorCodes;
2727
import org.firebirdsql.gds.TransactionParameterBuffer;
2828
import org.firebirdsql.gds.ng.wire.auth.legacy.LegacyAuthenticationPluginSpi;
29-
import org.firebirdsql.gds.ng.wire.auth.srp.*;
29+
import org.firebirdsql.gds.ng.wire.auth.srp.Srp224AuthenticationPluginSpi;
30+
import org.firebirdsql.gds.ng.wire.auth.srp.Srp256AuthenticationPluginSpi;
31+
import org.firebirdsql.gds.ng.wire.auth.srp.Srp384AuthenticationPluginSpi;
32+
import org.firebirdsql.gds.ng.wire.auth.srp.Srp512AuthenticationPluginSpi;
33+
import org.firebirdsql.gds.ng.wire.auth.srp.SrpAuthenticationPluginSpi;
34+
import org.firebirdsql.jaybird.props.PropertyNames;
3035
import org.firebirdsql.util.FirebirdSupportInfo;
3136
import org.junit.jupiter.api.Test;
3237
import org.junit.jupiter.api.extension.RegisterExtension;
@@ -37,18 +42,38 @@
3742
import java.lang.reflect.InvocationTargetException;
3843
import java.lang.reflect.Method;
3944
import java.sql.*;
40-
import java.util.*;
45+
import java.util.Calendar;
46+
import java.util.GregorianCalendar;
47+
import java.util.HashMap;
48+
import java.util.Map;
49+
import java.util.Properties;
50+
import java.util.TimeZone;
4151
import java.util.stream.Stream;
4252

43-
import static org.firebirdsql.common.FBTestProperties.*;
53+
import static org.firebirdsql.common.FBTestProperties.GDS_TYPE;
54+
import static org.firebirdsql.common.FBTestProperties.getConnectionViaDriverManager;
55+
import static org.firebirdsql.common.FBTestProperties.getDefaultPropertiesForConnection;
56+
import static org.firebirdsql.common.FBTestProperties.getDefaultSupportInfo;
57+
import static org.firebirdsql.common.FBTestProperties.getUrl;
4458
import static org.firebirdsql.common.FbAssumptions.assumeFeature;
4559
import static org.firebirdsql.common.assertions.CustomAssertions.assertThrowsForAutoCloseable;
4660
import static org.firebirdsql.common.matchers.GdsTypeMatchers.isEmbeddedType;
4761
import static org.firebirdsql.common.matchers.GdsTypeMatchers.isPureJavaType;
4862
import static org.firebirdsql.common.matchers.MatcherAssume.assumeThat;
49-
import static org.firebirdsql.common.matchers.SQLExceptionMatchers.*;
50-
import static org.firebirdsql.jaybird.fb.constants.TpbItems.*;
51-
import static org.hamcrest.CoreMatchers.*;
63+
import static org.firebirdsql.common.matchers.SQLExceptionMatchers.errorCodeEquals;
64+
import static org.firebirdsql.common.matchers.SQLExceptionMatchers.getFbMessage;
65+
import static org.firebirdsql.common.matchers.SQLExceptionMatchers.message;
66+
import static org.firebirdsql.common.matchers.SQLExceptionMatchers.sqlState;
67+
import static org.firebirdsql.jaybird.fb.constants.TpbItems.isc_tpb_no_rec_version;
68+
import static org.firebirdsql.jaybird.fb.constants.TpbItems.isc_tpb_nowait;
69+
import static org.firebirdsql.jaybird.fb.constants.TpbItems.isc_tpb_read_committed;
70+
import static org.firebirdsql.jaybird.fb.constants.TpbItems.isc_tpb_write;
71+
import static org.hamcrest.CoreMatchers.allOf;
72+
import static org.hamcrest.CoreMatchers.containsString;
73+
import static org.hamcrest.CoreMatchers.is;
74+
import static org.hamcrest.CoreMatchers.isA;
75+
import static org.hamcrest.CoreMatchers.not;
76+
import static org.hamcrest.CoreMatchers.startsWith;
5277
import static org.hamcrest.MatcherAssert.assertThat;
5378
import static org.junit.jupiter.api.Assertions.assertEquals;
5479
import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -530,5 +555,25 @@ void testNonAsciiLegacyAuth(String password) throws Exception {
530555
}
531556
}
532557

558+
/**
559+
* Rationale: see <a href="https://github.com/FirebirdSQL/jaybird/issues/940">jaybird#940</a>.
560+
* <p>
561+
* NOTE: The original problem (throwing a {@code NullPointerException}) this test checks for was only reproduced
562+
* with {@code AuthServer = Srp256} <em>if</em> {@code enableProtocol} is not set or does not enable protocol 10.
563+
* Having multiple authentication plugins configured server-side will make it work because then authentication will
564+
* only fail after the <em>identify</em> phase. In other words, in our regular test setup, this test will not
565+
* reproduce this error if it ever regresses.
566+
* </p>
567+
*/
568+
@Test
569+
void testUserDoesNotExist_enableProtocolNotSet() {
570+
var props = new Properties();
571+
props.setProperty(PropertyNames.user, "doesnotexist");
572+
props.setProperty(PropertyNames.password, "password");
573+
574+
assertThrows(SQLInvalidAuthorizationSpecException.class,
575+
() -> DriverManager.getConnection(getUrl(), props));
576+
}
577+
533578
}
534579

0 commit comments

Comments
 (0)