blob: b6859bb28fb20a38d8fc5de67d1369d9b688d10a [file] [log] [blame]
margaretha45211af2018-08-28 12:49:07 +02001package de.ids_mannheim.korap.misc;
Michael Hanlcb2d3f92016-06-02 17:34:06 +02002
Michael Hanlcb2d3f92016-06-02 17:34:06 +02003import static org.junit.Assert.assertEquals;
Michael Hanl2c3b0b12016-07-01 18:30:12 +02004import static org.junit.Assert.assertNotNull;
margaretha4b5c1412017-11-15 20:55:04 +01005
6import org.apache.commons.codec.binary.Base64;
7import org.junit.Test;
8import org.springframework.beans.factory.annotation.Autowired;
9
10import de.ids_mannheim.korap.authentication.BasicAuthentication;
margaretha56e8e552017-12-05 16:31:21 +010011import de.ids_mannheim.korap.authentication.http.AuthorizationData;
12import de.ids_mannheim.korap.authentication.http.HttpAuthorizationHandler;
13import de.ids_mannheim.korap.authentication.http.TransferEncoding;
margaretha4b5c1412017-11-15 20:55:04 +010014import de.ids_mannheim.korap.exceptions.KustvaktException;
15import de.ids_mannheim.korap.utils.StringUtils;
Michael Hanlcb2d3f92016-06-02 17:34:06 +020016
17/**
18 * Created by hanl on 29.05.16.
19 */
20public class StringUtilsTest {
21
margaretha4b5c1412017-11-15 20:55:04 +010022
Michael Hanlcb2d3f92016-06-02 17:34:06 +020023 @Test
24 public void testTextIToDoc () {
25 String textSigle = "WPD_AAA.02439";
26 String docSigle = "WPD_AAA";
27 assertEquals(docSigle, StringUtils.getDocSigle(textSigle));
28 assertEquals(docSigle, StringUtils.getDocSigle(docSigle));
29 }
30
31
32 @Test
margaretha4b5c1412017-11-15 20:55:04 +010033 public void testBasicHttpSplit () throws KustvaktException {
34 TransferEncoding transferEncoding = new TransferEncoding();
35 String s2 = new String(Base64.encodeBase64("test:testPass".getBytes()));
36 String[] f2 = transferEncoding.decodeBase64(s2);
37 assertEquals("test", f2[0]);
38 assertEquals("testPass", f2[1]);
39
40
41 HttpAuthorizationHandler handler = new HttpAuthorizationHandler();
42 String s1 = "basic "
43 + new String(Base64.encodeBase64("test:testPass".getBytes()));
margaretha2afb97d2017-12-07 19:18:44 +010044 AuthorizationData f1 = handler.parseAuthorizationHeaderValue(s1);
margaretha4b5c1412017-11-15 20:55:04 +010045 assertEquals(s2, f1.getToken());
Michael Hanlcb2d3f92016-06-02 17:34:06 +020046 }
Michael Hanl2c3b0b12016-07-01 18:30:12 +020047
Michael Hanlcb2d3f92016-06-02 17:34:06 +020048}