android/ui: add mdm key expiry notification window (#365)
Updates tailscale/corp#19743 Adjust the key expiry window and it's related notification based on the keyExpiry MDM setting. Default remains 24 hours. Logic moved to the viewModel. unitTest package added. It's a start! Signed-off-by: Jonathan Nobels <jonathan@tailscale.com>pull/368/head
parent
a2471d38cb
commit
17ad0c8cc0
@ -0,0 +1,30 @@
|
|||||||
|
// Copyright (c) Tailscale Inc & AUTHORS
|
||||||
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
|
||||||
|
package android.util;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is a mock class for the android.util.Log class. It is used to print log messages to the console.
|
||||||
|
*/
|
||||||
|
public class Log {
|
||||||
|
public static int d(String tag, String msg) {
|
||||||
|
System.out.println("DEBUG: " + tag + ": " + msg);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int i(String tag, String msg) {
|
||||||
|
System.out.println("INFO: " + tag + ": " + msg);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int w(String tag, String msg) {
|
||||||
|
System.out.println("WARN: " + tag + ": " + msg);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int e(String tag, String msg) {
|
||||||
|
System.out.println("ERROR: " + tag + ": " + msg);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,60 @@
|
|||||||
|
// Copyright (c) Tailscale Inc & AUTHORS
|
||||||
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
|
||||||
|
package com.tailcale.ipn.ui.util
|
||||||
|
|
||||||
|
import com.tailscale.ipn.ui.util.TimeUtil
|
||||||
|
import org.junit.Assert.assertEquals
|
||||||
|
import org.junit.Assert.assertNull
|
||||||
|
import org.junit.Test
|
||||||
|
import java.time.Duration
|
||||||
|
|
||||||
|
class TimeUtilTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun durationInvalidMsUnits() {
|
||||||
|
val input = "5s10ms"
|
||||||
|
val actual = TimeUtil.duration(input)
|
||||||
|
assertNull("Should return null", actual)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun durationInvalidUsUnits() {
|
||||||
|
val input = "5s10us"
|
||||||
|
val actual = TimeUtil.duration(input)
|
||||||
|
assertNull("Should return null", actual)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun durationTestHappyPath() {
|
||||||
|
val input = arrayOf("1.0y1.0w1.0d1.0h1.0m1.0s", "1s", "1m", "1h", "1d", "1w", "1y")
|
||||||
|
val expectedSeconds =
|
||||||
|
arrayOf((31536000 + 604800 + 86400 + 3600 + 60 + 1), 1, 60, 3600, 86400, 604800, 31536000)
|
||||||
|
val expected = expectedSeconds.map { Duration.ofSeconds(it.toLong()) }
|
||||||
|
val actual = input.map { TimeUtil.duration(it) }
|
||||||
|
assertEquals("Incorrect conversion", expected, actual)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testBadDurationString() {
|
||||||
|
val input = "1..0y1.0w1.0d1.0h1.0m1.0s"
|
||||||
|
val actual = TimeUtil.duration(input)
|
||||||
|
assertNull("Should return null", actual)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testBadDInputString() {
|
||||||
|
val input = "1.0yy1.0w1.0d1.0h1.0m1.0s"
|
||||||
|
val actual = TimeUtil.duration(input)
|
||||||
|
assertNull("Should return null", actual)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testIgnoreFractionalSeconds() {
|
||||||
|
val input = "10.9s"
|
||||||
|
val expectedSeconds = 10
|
||||||
|
val expected = Duration.ofSeconds(expectedSeconds.toLong())
|
||||||
|
val actual = TimeUtil.duration(input)
|
||||||
|
assertEquals("Should return $expectedSeconds seconds", expected, actual)
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue