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

New fxa client [firefox-android: bendk/new-fxa-client] #5851

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@

- Added the `enrollment_status` metric and defined a host metric callback handler interface ([#5857](https://github.com/mozilla/application-services/pull/5857)).

## FxA Client

### What's changed

- Major changes to the Kotlin wrappers. They now present a higher-level action/event system. The
goal here is to allow new consumers to use this directly, without a lot of extra code like
android-components needed.

## Rust log forwarder

### 🦊 What's Changed 🦊
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ buildscript {
ktlint_version = '0.50.0'
gradle_download_task_version = '5.2.1'
junit_version = '4.13.2'
mockk_version = '1.13.8'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drive-by for now 🚗 : The code moving here doesn't require mockk, and I would not recommend using it widely in the codebase given the troubles that we've had with it in fenix. We are now stuck with it and do not have an opportunity to easily remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is mockito recommended over mockk or should I be avoiding mocking libraries altogether?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mockito is preferable and we've used it in AC without issues for many years now. There were useful methods in the mockito-kotlin library that were helpful as well but to avoid adding more dependencies, we imported only those specific convenience functions.

If you can avoid a mocking library that would be ideal, but that is more of a philosophy than a good reason. 🙂

mockito_core_version = '5.5.0'
robolectric_core_version = '4.10.3'
rust_android_gradle_version = '0.9.3'
Expand Down
3 changes: 3 additions & 0 deletions components/fxa-client/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ dependencies {
api project(':sync15')

implementation "org.mozilla.telemetry:glean:$glean_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$kotlin_coroutines_version"

testImplementation "org.mozilla.telemetry:glean-native-forUnitTests:$glean_version"
testImplementation("io.mockk:mockk:${mockk_version}")
testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$kotlin_coroutines_version"
}

ext.configureUniFFIBindgen("../src/fxa_client.udl")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,55 +4,13 @@

package mozilla.appservices.fxaclient

/**
* Config represents the server endpoint configurations needed for the
* authentication flow.
*/
class Config constructor(
val server: FxaServer,
val clientId: String,
val redirectUri: String,
val tokenServerUrlOverride: String? = null,
) {
enum class Server(val rustServer: FxaServer) {
RELEASE(FxaServer.Release),
STABLE(FxaServer.Stable),
STAGE(FxaServer.Stage),
CHINA(FxaServer.China),
LOCALDEV(FxaServer.LocalDev),
;

val contentUrl get() = this.rustServer.contentUrl
}

constructor(
server: Server,
clientId: String,
redirectUri: String,
tokenServerUrlOverride: String? = null,
) : this(server.rustServer, clientId, redirectUri, tokenServerUrlOverride)

constructor(
contentUrl: String,
clientId: String,
redirectUri: String,
tokenServerUrlOverride: String? = null,
) : this(FxaServer.Custom(contentUrl), clientId, redirectUri, tokenServerUrlOverride)

val contentUrl get() = this.server.contentUrl

// Rust defines a config and server class that's virtually identically to these. We should
// remove the wrapper soon, but let's wait until we have a batch of breaking changes and do them
// all at once.
fun intoRustConfig() = FxaConfig(server, clientId, redirectUri, tokenServerUrlOverride)
fun FxaServer.isCustom() = this is FxaServer.Custom

fun FxaServer.contentUrl() = when (this) {
is FxaServer.Release -> "https://accounts.firefox.com"
is FxaServer.Stable -> "https://stable.dev.lcip.org"
is FxaServer.Stage -> "https://accounts.stage.mozaws.net"
is FxaServer.China -> "https://accounts.firefox.com.cn"
is FxaServer.LocalDev -> "http://127.0.0.1:3030"
is FxaServer.Custom -> this.url
}

val FxaServer.contentUrl: String
get() = when (this) {
is FxaServer.Release -> "https://accounts.firefox.com"
is FxaServer.Stable -> "https://stable.dev.lcip.org"
is FxaServer.Stage -> "https://accounts.stage.mozaws.net"
is FxaServer.China -> "https://accounts.firefox.com.cn"
is FxaServer.LocalDev -> "http://127.0.0.1:3030"
is FxaServer.Custom -> this.url
}
Loading