Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ca157f9c authored by Nishant Dande's avatar Nishant Dande
Browse files

Merge branch '1403-implement-anonymous-user' into 1456-integrate-anonymous-user

parents 7d348359 b2bfdee7
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -153,8 +153,6 @@ allOpen {

dependencies {

    implementation project(path: ':modules')

    // TODO: Add splitinstall-lib to a repo https://gitlab.e.foundation/e/os/backlog/-/issues/628
    api files('libs/splitinstall-lib.jar')

+19 −0
Original line number Diff line number Diff line
/*
 * Copyright MURENA SAS 2023
 * Apps  Quickly and easily install Android apps onto your device!
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */


plugins {
    id 'com.android.library'
    id 'org.jetbrains.kotlin.android'
+16 −57
Original line number Diff line number Diff line
package app.lounge

import app.lounge.model.AnonymousAuthDataRequestBody
import app.lounge.model.AnonymousAuthDataValidationRequestBody
import app.lounge.model.AuthDataResponse
import app.lounge.model.AuthDataValidationResponse
import app.lounge.networking.NetworkFetching
import app.lounge.networking.NetworkFetchingRetrofitAPI
import app.lounge.networking.NetworkFetchingRetrofitImpl
import app.lounge.login.anonymous.AnonymousUser
import app.lounge.login.anonymous.AnonymousUserRetrofitAPI
import app.lounge.login.anonymous.AnonymousUserRetrofitImpl
import app.lounge.networking.NetworkResult
import com.aurora.gplayapi.data.models.AuthData
import kotlinx.coroutines.runBlocking
import okhttp3.OkHttpClient
import org.junit.Test
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.io.InterruptedIOException
import java.util.Properties
import java.util.concurrent.TimeUnit

class NetworkFetchingAPITest {
class AnonymousUserAPITest {

    companion object {
        var authData: AuthDataResponse? =  null
        var authData: AuthData? =  null
    }

    @Test
    fun test1OnSuccessReturnsAuthData() = runBlocking {
        authData = networkFetchingToken.requestAuthData(
    fun testOnSuccessReturnsAuthData() = runBlocking {
        val response = anonymousUser.requestAuthData(
            anonymousAuthDataRequestBody = requestBodyData,
        )
        assert(authData is AuthDataResponse) { "Assert!! Success must return data" }
        when(response){
            is NetworkResult.Success -> authData = response.data
            else -> {}
        }

    @Test
    fun test2OnSuccessReturnsLoginData() = runBlocking {
        var result: AuthDataValidationResponse? = null
        authData?.let { authData ->
            authData.dfeCookie = "null"

            result = networkFetchingToken.requestAuthDataValidation(
                anonymousAuthDataValidationRequestBody = AnonymousAuthDataValidationRequestBody(
                    authDataResponse = authData
                )
            )
        assert(authData is AuthData) { "Assert!! Success must return data" }
    }

        assert(authData is AuthDataResponse) { "Assert!! AuthData must be present" }
        assert(result is AuthDataValidationResponse) { "Assert!! `response` must have data" }
    }

    @Test
    fun test3OnTimeoutFailureReturnsError(): Unit = runBlocking {
        var failure: Exception = Exception("No Error")
        authData?.let { authData ->
            authData.dfeCookie = "null"

            try {
                networkFetchingTimeoutGoogle.requestAuthDataValidation(
                    anonymousAuthDataValidationRequestBody = AnonymousAuthDataValidationRequestBody(
                        authDataResponse = authData
                    )
                )
            } catch (e: InterruptedIOException) { failure = e }
        }
        assert(authData is AuthDataResponse) { "Assert!! AuthData must be present" }
        assert(failure is InterruptedIOException) { "Assert!! Timeout Failure callback must call" }
    }

    private fun retrofitTestConfig(
        baseUrl: String,
@@ -78,20 +47,9 @@ class NetworkFetchingAPITest {
        )
        .build()

    private val eCloudTest = retrofitTestConfig(NetworkFetchingRetrofitAPI.tokenBaseURL)
    private val googleTest = retrofitTestConfig(NetworkFetchingRetrofitAPI.googlePlayBaseURL)
    private val googleTestTimeout = retrofitTestConfig(
        NetworkFetchingRetrofitAPI.googlePlayBaseURL, 50L)
    private val eCloudTest = retrofitTestConfig(AnonymousUserRetrofitAPI.tokenBaseURL)

    private val networkFetchingToken: NetworkFetching = NetworkFetchingRetrofitImpl(
        eCloud = eCloudTest,
        google = googleTest
    )

    private val networkFetchingTimeoutGoogle: NetworkFetching = NetworkFetchingRetrofitImpl(
        eCloud = eCloudTest,
        google = googleTestTimeout
    )
    private val anonymousUser: AnonymousUser = AnonymousUserRetrofitImpl(eCloud = eCloudTest)

    private val requestBodyData = AnonymousAuthDataRequestBody(
        properties = testSystemProperties,
@@ -139,3 +97,4 @@ val testSystemProperties = Properties().apply {
    setProperty("CellOperator", "310")
    setProperty("SimOperator", "38")
}
+28 −23
Original line number Diff line number Diff line
/*
 * Copyright MURENA SAS 2023
 * Apps  Quickly and easily install Android apps onto your device!
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */


package app.lounge.di

import app.lounge.networking.NetworkFetching
import app.lounge.networking.NetworkFetchingRetrofitAPI
import app.lounge.networking.NetworkFetchingRetrofitImpl
import app.lounge.login.anonymous.AnonymousUser
import app.lounge.login.anonymous.AnonymousUserRetrofitAPI
import app.lounge.login.anonymous.AnonymousUserRetrofitImpl
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
@@ -40,19 +59,7 @@ internal object NetworkModule {
    ): Retrofit {
        return retrofit(
            okHttpClient = okHttpClient,
            baseUrl = NetworkFetchingRetrofitAPI.tokenBaseURL
        )
    }

    @Provides
    @Singleton
    @Named("GoogleRetrofit")
    internal fun provideGoogleRetrofit(
        okHttpClient: OkHttpClient
    ): Retrofit {
        return retrofit(
            okHttpClient = okHttpClient,
            baseUrl = NetworkFetchingRetrofitAPI.googlePlayBaseURL
            baseUrl = AnonymousUserRetrofitAPI.tokenBaseURL
        )
    }

@@ -81,13 +88,11 @@ internal object NetworkModule {

    @Provides
    @Singleton
    fun provideNetworkFetching(
        @Named("ECloudRetrofit") ecloud: Retrofit,
        @Named("GoogleRetrofit") google: Retrofit,
    ) : NetworkFetching {
        return NetworkFetchingRetrofitImpl(
            eCloud = ecloud,
            google = google
    fun provideAnonymousUser(
        @Named("ECloudRetrofit") ecloud: Retrofit
    ) : AnonymousUser {
        return AnonymousUserRetrofitImpl(
            eCloud = ecloud
        )
    }

+19 −0
Original line number Diff line number Diff line
/*
 * Copyright MURENA SAS 2023
 * Apps  Quickly and easily install Android apps onto your device!
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */


package app.lounge.extension

import com.google.gson.Gson
Loading