Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/fir 21173 add identity support #238

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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
7 changes: 5 additions & 2 deletions .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ on:
description: 'Database - a new one will be created if not provided'
required: false
default: ''
account:
description: 'Account'
required: true
alexradzin marked this conversation as resolved.
Show resolved Hide resolved
environment:
description: 'Environment to run the tests against'
type: choice
Expand Down Expand Up @@ -66,7 +69,7 @@ jobs:
fi

- name: Run integration tests
run: ./gradlew integrationTest -Ddb=${{ steps.find-database-name.outputs.database_name }} -Dapi=api.${{ github.event.inputs.environment }}.firebolt.io -Dpassword="${{ env.SERVICE_ACCOUNT_SECRET }}" -Duser="${{ env.SERVICE_ACCOUNT_ID }}"
run: ./gradlew integrationTest -Ddb=${{ steps.find-database-name.outputs.database_name }} -Denv=${{ github.event.inputs.environment }} -Dpassword="${{ env.SERVICE_ACCOUNT_SECRET }}" -Duser="${{ env.SERVICE_ACCOUNT_ID }} -Daccount=${{ github.event.inputs.account }}"

- name: "Foresight: Analyze Test Results"
uses: runforesight/foresight-test-kit-action@v1
Expand All @@ -77,4 +80,4 @@ jobs:
test_path: ./build/test-results/
tags: |
type:"integration"
language:"Java"
language:"Java"
56 changes: 43 additions & 13 deletions src/integrationTest/java/integration/ConnectionInfo.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,59 @@
package integration;

import lombok.Value;

import java.util.Optional;

@Value
import static java.lang.System.getProperty;

public class ConnectionInfo {
private static ConnectionInfo INSTANCE;
String password;
String user;
String api;
String database;
private static volatile ConnectionInfo INSTANCE;
private final String principal;
private final String secret;
private final String env;
private final String database;
private final String account;
private final String engine;

private ConnectionInfo() {
password = Optional.ofNullable(System.getProperty("password")).map(p -> p.replace("\"", "")).orElse(null);
user = Optional.ofNullable(System.getProperty("user")).map(u -> u.replace("\"", "")).orElse(null);
api = System.getProperty("api");
database = System.getProperty("db");
principal = Optional.ofNullable(getProperty("client_id", getProperty("user"))).map(u -> u.replace("\"", "")).orElse(null);
alexradzin marked this conversation as resolved.
Show resolved Hide resolved
secret = Optional.ofNullable(getProperty("client_secret", getProperty("password"))).map(p -> p.replace("\"", "")).orElse(null);
env = getProperty("env");
database = getProperty("db");
account = getProperty("account");
engine = getProperty("engine");
}

public static ConnectionInfo getInstance() {
if (INSTANCE == null) {
INSTANCE = new ConnectionInfo();
synchronized (ConnectionInfo.class) {
if (INSTANCE == null) {
INSTANCE = new ConnectionInfo();
}
}
}
return INSTANCE;
}

public String getPrincipal() {
return principal;
}

public String getSecret() {
return secret;
}

public String getEnv() {
return env;
}

public String getDatabase() {
return database;
}

public String getAccount() {
return account;
}

public String getEngine() {
return engine;
}
}
38 changes: 24 additions & 14 deletions src/integrationTest/java/integration/IntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,31 @@
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public abstract class IntegrationTest {

private static final String JDBC_URL_PREFIX = "jdbc:firebolt:";

protected Connection createLocalConnection(String queryParams) throws SQLException {
return DriverManager.getConnection(
"jdbc:firebolt://localhost" + "/" + integration.ConnectionInfo.getInstance().getDatabase()
+ queryParams,
integration.ConnectionInfo.getInstance().getUser(),
integration.ConnectionInfo.getInstance().getPassword());
JDBC_URL_PREFIX + integration.ConnectionInfo.getInstance().getDatabase()
+ queryParams + "&host=localhost" + getAccountParam(),
integration.ConnectionInfo.getInstance().getPrincipal(),
integration.ConnectionInfo.getInstance().getSecret());
}

protected Connection createConnection() throws SQLException {
return DriverManager.getConnection(
"jdbc:firebolt://" + integration.ConnectionInfo.getInstance().getApi() + "/"
+ integration.ConnectionInfo.getInstance().getDatabase(),
integration.ConnectionInfo.getInstance().getUser(),
integration.ConnectionInfo.getInstance().getPassword());
JDBC_URL_PREFIX
+ integration.ConnectionInfo.getInstance().getDatabase() + "?" + getEnvParam() + getAccountParam() ,
integration.ConnectionInfo.getInstance().getPrincipal(),
integration.ConnectionInfo.getInstance().getSecret());
}

protected Connection createConnection(String engine) throws SQLException {
return DriverManager.getConnection(
"jdbc:firebolt://" + integration.ConnectionInfo.getInstance().getApi() + "/"
+ integration.ConnectionInfo.getInstance().getDatabase()
+ Optional.ofNullable(engine).map(e -> "?engine=" + e).orElse(""),
integration.ConnectionInfo.getInstance().getUser(),
integration.ConnectionInfo.getInstance().getPassword());
JDBC_URL_PREFIX +
integration.ConnectionInfo.getInstance().getDatabase()
+ Optional.ofNullable(engine).map(e -> "?" + getEnvParam() +"&engine=" + e + getAccountParam() ).orElse("?" + getEnvParam() + getAccountParam()),
integration.ConnectionInfo.getInstance().getPrincipal(),
integration.ConnectionInfo.getInstance().getSecret());
}

protected void setParam(Connection connection, String name, String value) throws SQLException {
Expand All @@ -53,7 +55,7 @@ protected void setParam(Connection connection, String name, String value) throws

@SneakyThrows
protected void executeStatementFromFile(String path) {
executeStatementFromFile(path, null);
executeStatementFromFile(path, integration.ConnectionInfo.getInstance().getEngine());
}

@SneakyThrows
Expand All @@ -70,4 +72,12 @@ protected void removeExistingClient() throws NoSuchFieldException, IllegalAccess
field.set(null, null);
}

private String getAccountParam() {
return "&account=" + integration.ConnectionInfo.getInstance().getAccount();
}

private String getEnvParam() {
return "&env=" + integration.ConnectionInfo.getInstance().getEnv();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,9 @@ void shouldFailSQLInjectionAttempt() throws SQLException {
private QueryResult createExpectedResult(List<List<?>> expectedRows) {
return QueryResult.builder().databaseName(ConnectionInfo.getInstance().getDatabase())
.tableName("prepared_statement_test")
.columns(Arrays.asList(QueryResult.Column.builder().name("sales").type(FireboltDataType.BIG_INT).build(),
QueryResult.Column.builder().name("make").type(FireboltDataType.TEXT).build()))
.columns(
Arrays.asList(QueryResult.Column.builder().name("sales").type(FireboltDataType.BIG_INT).build(),
QueryResult.Column.builder().name("make").type(FireboltDataType.TEXT).build()))
.rows(expectedRows).build();

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ void afterEach() {
executeStatementFromFile("/statements/statement/cleanup.sql");
}

@Test
void shouldSelect1() throws SQLException {
try (Connection connection = this.createConnection(); Statement statement = connection.createStatement()) {
statement.executeQuery("SELECT 1;");
assertNotNull(statement.executeQuery("SELECT 1;"));
}
}

@Test
void shouldReuseStatementWhenNotCloseOnCompletion() throws SQLException {
try (Connection connection = this.createConnection(); Statement statement = connection.createStatement()) {
Expand Down
12 changes: 12 additions & 0 deletions src/integrationTest/java/integration/tests/TimestampTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,18 @@ void shouldRemoveOffsetDIffWhenTimestampOffsetHasChangedCET() throws SQLExceptio
}
}

@Test
void shouldHaveCorrectInfo() throws SQLException {
try (Connection connection = this.createConnection("system");
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery("SELECT 3::decimal")) {
resultSet.next();
assertEquals(9, resultSet.getMetaData().getScale(1));
assertEquals(38, resultSet.getMetaData().getPrecision(1));
}

}
alexradzin marked this conversation as resolved.
Show resolved Hide resolved

@Test
void shouldReturnTimestampFromTimestampntz() throws SQLException {
try (Connection connection = this.createConnection();
Expand Down
10 changes: 3 additions & 7 deletions src/main/java/com/firebolt/FireboltDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
public class FireboltDriver implements Driver {

public static final String JDBC_FIREBOLT = "jdbc:firebolt:";
private static final String JDBC_FIREBOLT_PREFIX = JDBC_FIREBOLT + "//";
private static final String JDBC_FIREBOLT_PREFIX = JDBC_FIREBOLT;
alexradzin marked this conversation as resolved.
Show resolved Hide resolved

static {
try {
Expand All @@ -30,11 +30,7 @@ public class FireboltDriver implements Driver {

@Override
public Connection connect(String url, Properties connectionSettings) throws SQLException {
if (!acceptsURL(url)) {
return null;
} else {
return new FireboltConnection(url, connectionSettings);
}
return acceptsURL(url) ? new FireboltConnection(url, connectionSettings) : null;
}

@Override
Expand All @@ -43,7 +39,7 @@ public boolean acceptsURL(String url) {
}

@Override
public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException {
public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) {
return PropertyUtil.getPropertyInfo(url, info);
}

Expand Down
65 changes: 0 additions & 65 deletions src/main/java/com/firebolt/jdbc/Query.java

This file was deleted.

5 changes: 3 additions & 2 deletions src/main/java/com/firebolt/jdbc/QueryResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
/**
* Class containing a query result that can be used to create a
* {@link com.firebolt.jdbc.resultset.FireboltResultSet}
* It is particularly useful for metadata methods as a ResulSet containing metadata info must be returned.
*/
@Builder
@Value
Expand All @@ -36,8 +37,8 @@ public String toString() {
StringBuilder stringBuilder = new StringBuilder();
this.appendWithListValues(stringBuilder, columns.stream().map(Column::getName).collect(Collectors.toList()));
stringBuilder.append(NEXT_LINE);
this.appendWithListValues(stringBuilder, columns.stream().map(Column::getType)
.map(FireboltDataType::getAliases).map( aliases -> aliases[0]).collect(Collectors.toList()));
this.appendWithListValues(stringBuilder, columns.stream().map(Column::getType).map(FireboltDataType::getAliases)
.map(aliases -> aliases[0]).collect(Collectors.toList()));
stringBuilder.append(NEXT_LINE);

for (int i = 0; i < rows.size(); i++) {
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/firebolt/jdbc/client/FireboltClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ protected FireboltClient(OkHttpClient httpClient, FireboltConnection connection,
customClients != null ? customClients : "");
}

protected <T> T getResource(String uri, String accessToken, Class<T> valueType)
throws IOException, FireboltException {
return getResource(uri, uri, accessToken, valueType);
}

protected <T> T getResource(String uri, String host, String accessToken, Class<T> valueType)
throws IOException, FireboltException {
Request rq = createGetRequest(uri, accessToken);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.firebolt.jdbc.client.account;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.Objects;

public class FireboltAccount {
@JsonProperty
private final String id;
@JsonProperty
private final String region;

@JsonCreator
public FireboltAccount(@JsonProperty("id") String id, @JsonProperty("region") String region) {
this.id = id;
this.region = region;
}

public String getId() {
return id;
}

public String getRegion() {
return region;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
FireboltAccount account = (FireboltAccount) o;
return Objects.equals(id, account.id) && Objects.equals(region, account.region);
}

@Override
public int hashCode() {
return Objects.hash(id, region);
}
}
Loading