taler-android

Android apps for GNU Taler (wallet, PoS, cashier)
Log | Files | Refs | README | LICENSE

TalerUriTest.kt (2439B)


      1 /*
      2  * This file is part of GNU Taler
      3  * (C) 2020 Taler Systems S.A.
      4  *
      5  * GNU Taler is free software; you can redistribute it and/or modify it under the
      6  * terms of the GNU General Public License as published by the Free Software
      7  * Foundation; either version 3, or (at your option) any later version.
      8  *
      9  * GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
     10  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
     11  * A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
     12  *
     13  * You should have received a copy of the GNU General Public License along with
     14  * GNU Taler; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
     15  */
     16 
     17 package net.taler.common
     18 
     19 import net.taler.common.TalerUri.parseWithdrawUri
     20 import org.junit.Assert.assertEquals
     21 import org.junit.Assert.assertNull
     22 import org.junit.Test
     23 
     24 class TalerUriTest {
     25 
     26     @Test
     27     fun testParseWithdrawUri() {
     28         // correct parsing
     29         var uri = "taler://withdraw/bank.example.com/12345"
     30         var expected = TalerUri.WithdrawUriResult("https://bank.example.com/", "12345")
     31         assertEquals(expected, parseWithdrawUri(uri))
     32 
     33         // correct parsing with insecure http
     34         uri = "taler+http://withdraw/bank.example.org/foo"
     35         expected = TalerUri.WithdrawUriResult("http://bank.example.org/", "foo")
     36         assertEquals(expected, parseWithdrawUri(uri))
     37 
     38         // correct parsing with long path
     39         uri = "taler://withdraw/bank.example.com/foo/bar/23/42/1337/1234567890"
     40         expected =
     41             TalerUri.WithdrawUriResult("https://bank.example.com/foo/bar/23/42/1337", "1234567890")
     42         assertEquals(expected, parseWithdrawUri(uri))
     43 
     44         // rejects incorrect scheme
     45         uri = "talerx://withdraw/bank.example.com/12345"
     46         assertNull(parseWithdrawUri(uri))
     47 
     48         // rejects incorrect authority
     49         uri = "taler://withdrawx/bank.example.com/12345"
     50         assertNull(parseWithdrawUri(uri))
     51 
     52         // rejects incorrect authority with insecure http
     53         uri = "taler+http://withdrawx/bank.example.com/12345"
     54         assertNull(parseWithdrawUri(uri))
     55 
     56         // rejects empty withdrawalId
     57         uri = "taler://withdraw/bank.example.com//"
     58         assertNull(parseWithdrawUri(uri))
     59 
     60         // rejects empty path and withdrawalId
     61         uri = "taler://withdraw/bank.example.com////"
     62         assertNull(parseWithdrawUri(uri))
     63     }
     64 
     65 }