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

Commit 4281d276 authored by Arpan Kaphle's avatar Arpan Kaphle
Browse files

Testing all the Calling App UID Track Emits

These test the rest of the calling app uid emits - so now initial, total
aggregate, and final no uid are tested to not throw errors. This also
ended up adding the rest of the provider app uid emits - so candidate,
authentication, get, and final.

Bug: 273339472
Test: Build and these are Unit Tests
Change-Id: I7bfd5a04ac16b6c260a2f786ce8b6b609f57217d
parent 2907102b
Loading
Loading
Loading
Loading
+116 −0
Original line number Diff line number Diff line
@@ -15,14 +15,27 @@
 */
package com.android.server.credentials;

import android.content.Context;

import androidx.test.core.app.ApplicationProvider;
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;

import com.android.server.credentials.metrics.BrowsedAuthenticationMetric;
import com.android.server.credentials.metrics.CandidateAggregateMetric;
import com.android.server.credentials.metrics.CandidateBrowsingPhaseMetric;
import com.android.server.credentials.metrics.ChosenProviderFinalPhaseMetric;
import com.android.server.credentials.metrics.InitialPhaseMetric;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.security.cert.CertificateException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Given the secondary-system nature of the MetricUtilities, we expect absolutely nothing to
 * throw an error. If one presents itself, that is problematic.
@@ -33,6 +46,11 @@ import org.junit.runner.RunWith;
@SmallTest
public final class MetricUtilitiesTest {

    @Before
    public void setUp() throws CertificateException {
        final Context context = ApplicationProvider.getApplicationContext();
    }

    @Test
    public void logApiCalledInitialPhase_nullInitPhaseMetricAndNegativeSequence_success() {
        MetricUtilities.logApiCalledInitialPhase(null, -1);
@@ -49,4 +67,102 @@ public final class MetricUtilitiesTest {
                MetricUtilities.getHighlyUniqueInteger());
        MetricUtilities.logApiCalledInitialPhase(validInitPhaseMetric, 1);
    }

    @Test
    public void logApiCalledTotalCandidate_nullCandidateNegativeSequence_success() {
        MetricUtilities.logApiCalledAggregateCandidate(null, -1);
    }

    @Test
    public void logApiCalledTotalCandidate_invalidCandidatePhasePositiveSequence_success() {
        MetricUtilities.logApiCalledAggregateCandidate(new CandidateAggregateMetric(-1), 1);
    }

    @Test
    public void logApiCalledTotalCandidate_validPhaseMetric_success() {
        MetricUtilities.logApiCalledAggregateCandidate(
                new CandidateAggregateMetric(MetricUtilities.getHighlyUniqueInteger()), 1);
    }

    @Test
    public void logApiCalledNoUidFinal_nullNoUidFinalNegativeSequenceAndStatus_success() {
        MetricUtilities.logApiCalledNoUidFinal(null, null,
                -1, -1);
    }

    @Test
    public void logApiCalledNoUidFinal_invalidNoUidFinalPhasePositiveSequenceAndStatus_success() {
        MetricUtilities.logApiCalledNoUidFinal(new ChosenProviderFinalPhaseMetric(-1, -1),
                List.of(new CandidateBrowsingPhaseMetric()), 1, 1);
    }

    @Test
    public void logApiCalledNoUidFinal_validNoUidFinalMetric_success() {
        MetricUtilities.logApiCalledNoUidFinal(
                new ChosenProviderFinalPhaseMetric(MetricUtilities.getHighlyUniqueInteger(),
                        MetricUtilities.getHighlyUniqueInteger()),
                List.of(new CandidateBrowsingPhaseMetric()), 1, 1);
    }

    @Test
    public void logApiCalledCandidate_nullMapNullInitFinalNegativeSequence_success() {
        MetricUtilities.logApiCalledCandidatePhase(null, -1,
                null);
    }

    @Test
    public void logApiCalledCandidate_invalidProvidersCandidatePositiveSequence_success() {
        Map<String, ProviderSession> testMap = new HashMap<>();
        testMap.put("s", null);
        MetricUtilities.logApiCalledCandidatePhase(testMap, 1,
                null);
    }

    @Test
    public void logApiCalledCandidateGet_nullMapFinalNegativeSequence_success() {
        MetricUtilities.logApiCalledCandidateGetMetric(null, -1);
    }

    @Test
    public void logApiCalledCandidateGet_invalidProvidersCandidatePositiveSequence_success() {
        Map<String, ProviderSession> testMap = new HashMap<>();
        testMap.put("s", null);
        MetricUtilities.logApiCalledCandidateGetMetric(testMap, 1);
    }

    @Test
    public void logApiCalledAuthMetric_nullAuthMetricNegativeSequence_success() {
        MetricUtilities.logApiCalledAuthenticationMetric(null, -1);
    }

    @Test
    public void logApiCalledAuthMetric_invalidAuthMetricPositiveSequence_success() {
        MetricUtilities.logApiCalledAuthenticationMetric(new BrowsedAuthenticationMetric(-1), 1);
    }

    @Test
    public void logApiCalledAuthMetric_nullAuthMetricPositiveSequence_success() {
        MetricUtilities.logApiCalledAuthenticationMetric(
                new BrowsedAuthenticationMetric(MetricUtilities.getHighlyUniqueInteger()), -1);
    }

    @Test
    public void logApiCalledFinal_nullFinalNegativeSequenceAndStatus_success() {
        MetricUtilities.logApiCalledFinalPhase(null, null,
                -1, -1);
    }

    @Test
    public void logApiCalledFinal_invalidFinalPhasePositiveSequenceAndStatus_success() {
        MetricUtilities.logApiCalledFinalPhase(new ChosenProviderFinalPhaseMetric(-1, -1),
                List.of(new CandidateBrowsingPhaseMetric()), 1, 1);
    }

    @Test
    public void logApiCalledFinal_validFinalMetric_success() {
        MetricUtilities.logApiCalledFinalPhase(
                new ChosenProviderFinalPhaseMetric(MetricUtilities.getHighlyUniqueInteger(),
                        MetricUtilities.getHighlyUniqueInteger()),
                List.of(new CandidateBrowsingPhaseMetric()), 1, 1);
    }
}