Modern-Apps.git
Publicgit clone https://git.maproj.org/Modern-Apps.gitModern-Apps.git / communicate-dev / src / test / java / com / vayunmathur / communicate / signal / SignalCdsiTest.kt
SignalCdsiTest.kt42 lines · 1.3 KiBRaw
| 1 | package com.vayunmathur.communicate.signal |
| 2 | |
| 3 | import com.vayunmathur.communicate.data.signal.transport.SignalCdsi |
| 4 | import kotlin.test.Test |
| 5 | import kotlin.test.assertEquals |
| 6 | import kotlin.test.assertNull |
| 7 | |
| 8 | /** |
| 9 | * Parser vectors for `GET /v2/directory/auth`. These are enclave credentials, distinct from the |
| 10 | * account's own auth, so a partial response must be rejected rather than used to attempt a lookup. |
| 11 | */ |
| 12 | class SignalCdsiTest { |
| 13 | private fun parse(body: String) = SignalCdsi.parseCredentials(body, warn = {}) |
| 14 | |
| 15 | @Test |
| 16 | fun parsesCredentials() { |
| 17 | val creds = parse("""{"username":"u1","password":"p1"}""") |
| 18 | assertEquals("u1", creds?.username) |
| 19 | assertEquals("p1", creds?.password) |
| 20 | } |
| 21 | |
| 22 | @Test |
| 23 | fun ignoresUnknownFields() { |
| 24 | val creds = parse("""{"username":"u1","password":"p1","extra":123}""") |
| 25 | assertEquals("u1", creds?.username) |
| 26 | } |
| 27 | |
| 28 | @Test |
| 29 | fun rejectsPartialOrEmptyCredentials() { |
| 30 | assertNull(parse("""{"username":"u1"}""")) |
| 31 | assertNull(parse("""{"password":"p1"}""")) |
| 32 | assertNull(parse("""{"username":"","password":"p1"}""")) |
| 33 | assertNull(parse("""{"username":"u1","password":""}""")) |
| 34 | assertNull(parse("""{}""")) |
| 35 | } |
| 36 | |
| 37 | @Test |
| 38 | fun rejectsJunk() { |
| 39 | assertNull(parse("not json")) |
| 40 | assertNull(parse("")) |
| 41 | } |
| 42 | } |