Skip to content

Commit

Permalink
Auth improvements (#503)
Browse files Browse the repository at this point in the history
* Simplify mock credential

* Increase HttpTimeout to 60s

* Move debug helper out of Main.kt

* Fix lint issues
  • Loading branch information
bootstraponline authored Feb 23, 2019
1 parent f28e163 commit fcb2cec
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 28 deletions.
5 changes: 0 additions & 5 deletions test_runner/src/main/kotlin/ftl/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,8 @@ class Main : Runnable {
private var printVersion = false

companion object {
init {
// GoogleApiLogger.logAllToStdout()
}

@JvmStatic
fun main(args: Array<String>) {
// val args = arrayOf("firebase", "test", "android", "run") // for debugging. run test from IntelliJ IDEA
CommandLine.run<Runnable>(Main(), System.out, *args)
}
}
Expand Down
12 changes: 3 additions & 9 deletions test_runner/src/main/kotlin/ftl/config/FtlConstants.kt
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package ftl.config

import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport
import com.google.api.client.googleapis.testing.auth.oauth2.MockGoogleCredential
import com.google.api.client.googleapis.util.Utils
import com.google.api.client.http.HttpRequestInitializer
import com.google.api.client.http.javanet.NetHttpTransport
import com.google.api.client.json.JsonFactory
import com.google.auth.http.HttpCredentialsAdapter
import com.google.auth.oauth2.ServiceAccountCredentials
import ftl.args.AndroidArgs
import ftl.args.IArgs
import ftl.args.IosArgs
import ftl.http.TimeoutHttpRequestInitializer
import ftl.http.HttpTimeoutIncrease
import java.nio.file.Path
import java.nio.file.Paths

Expand Down Expand Up @@ -48,18 +46,14 @@ object FtlConstants {

val credential: HttpRequestInitializer by lazy {
if (useMock) {
TimeoutHttpRequestInitializer(
MockGoogleCredential.Builder()
.setTransport(MockGoogleCredential.newMockHttpTransportWithSampleTokenResponse())
.build()
)
HttpRequestInitializer {}
} else {
// Authenticate with https://github.com/googleapis/google-auth-library-java
// Scope is required.
// https://developers.google.com/identity/protocols/googlescopes
// https://developers.google.com/identity/protocols/application-default-credentials
// https://cloud.google.com/sdk/gcloud/reference/alpha/compute/instances/set-scopes
HttpCredentialsAdapter(
HttpTimeoutIncrease(
ServiceAccountCredentials.getApplicationDefault()
.createScoped(listOf("https://www.googleapis.com/auth/cloud-platform"))
)
Expand Down
15 changes: 15 additions & 0 deletions test_runner/src/main/kotlin/ftl/http/HttpTimeoutIncrease.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package ftl.http

import com.google.api.client.http.HttpRequest
import com.google.auth.Credentials
import com.google.auth.http.HttpCredentialsAdapter

/** Resolves timeout flakiness by increasing the timeout to 60s (the default is 20s) **/
class HttpTimeoutIncrease(credentials: Credentials) : HttpCredentialsAdapter(credentials) {
override fun initialize(request: HttpRequest?) {
super.initialize(request)

request?.connectTimeout = 60 * 1000
request?.readTimeout = 60 * 1000
}
}

This file was deleted.

14 changes: 14 additions & 0 deletions test_runner/src/test/kotlin/Debug.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import ftl.Main
import picocli.CommandLine

object Debug {

@JvmStatic
@Suppress("UnusedPrivateMember") // Suppress detekt rule
fun main(args: Array<String>) {
// GoogleApiLogger.logAllToStdout()

val arguments = arrayOf("firebase", "test", "android", "run") // for debugging. run test from IntelliJ IDEA
CommandLine.run<Runnable>(Main(), System.out, *arguments)
}
}

0 comments on commit fcb2cec

Please sign in to comment.