Added tests for HttpAcessLogParser class.
This commit is contained in:
parent
112afd61ed
commit
0f67780f1b
2 changed files with 100 additions and 0 deletions
|
@ -84,6 +84,23 @@ public class HttpAccessLogParser
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses the log.
|
||||||
|
*
|
||||||
|
* @param line
|
||||||
|
* the line
|
||||||
|
* @return the http access log
|
||||||
|
*/
|
||||||
|
public static HttpAccessLog parseLog(final String line)
|
||||||
|
{
|
||||||
|
HttpAccessLog result;
|
||||||
|
|
||||||
|
result = parseLog(line, COMBINED_PATTERN, DATETIME_FORMATTER);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses the log.
|
* Parses the log.
|
||||||
*
|
*
|
||||||
|
|
|
@ -0,0 +1,83 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2021-2024 Christian Pierre MOMON <christian@momon.org>
|
||||||
|
*
|
||||||
|
* This file is part of StatoolInfos, simple key value database.
|
||||||
|
*
|
||||||
|
* StatoolInfos is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* StatoolInfos is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with StatoolInfos. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package fr.devinsy.statoolinfos.metrics.httpaccess;
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.Level;
|
||||||
|
import org.apache.logging.log4j.core.config.Configurator;
|
||||||
|
import org.apache.logging.log4j.core.config.DefaultConfiguration;
|
||||||
|
import org.junit.AfterClass;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import fr.devinsy.statoolinfos.core.StatoolInfosException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Class HttpAccessLogParserTest.
|
||||||
|
*/
|
||||||
|
public class HttpAccessLogParserTest
|
||||||
|
{
|
||||||
|
private static org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(HttpAccessLogParserTest.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test 01.
|
||||||
|
*
|
||||||
|
* @throws Exception
|
||||||
|
* the exception
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void test01() throws Exception
|
||||||
|
{
|
||||||
|
// Nominal line.
|
||||||
|
String line = "172.104.137.47 - - [30/Apr/2023:23:25:15 +0200] \"GET /default.jsp HTTP/1.1\" 302 534 \"-\" \"curl/7.54.0\"";
|
||||||
|
Assert.assertNotNull(HttpAccessLogParser.parseLog(line));
|
||||||
|
|
||||||
|
// Line with a \" in request string.
|
||||||
|
line = "172.104.137.47 - - [30/Apr/2023:23:25:15 +0200] \"GET /def\\\"ault.jsp HTTP/1.1\" 302 534 \"-\" \"curl/7.54.0\"";
|
||||||
|
Assert.assertNotNull(HttpAccessLogParser.parseLog(line));
|
||||||
|
|
||||||
|
// Line with many \".
|
||||||
|
line = "10.141.57.46 - - [28/Apr/2023:13:46:34 +0200] \"GET /?\\\"<?=print(9347655345-4954366)?>\\\" HTTP/1.1\" 302 5143 \"https://www.gaagle.com/\\\"<?=print(9347655345-4954366);?>\\\"\" \"Mozilliqa\\\"<?=print(9347655345-4954366);?>\\\"\"";
|
||||||
|
Assert.assertNotNull(HttpAccessLogParser.parseLog(line));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* After class.
|
||||||
|
*
|
||||||
|
* @throws StatoolInfosException
|
||||||
|
* the Juga exception
|
||||||
|
*/
|
||||||
|
@AfterClass
|
||||||
|
public static void afterClass() throws StatoolInfosException
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Before class.
|
||||||
|
*
|
||||||
|
* @throws StatoolInfosException
|
||||||
|
* the Juga exception
|
||||||
|
*/
|
||||||
|
@BeforeClass
|
||||||
|
public static void beforeClass() throws StatoolInfosException
|
||||||
|
{
|
||||||
|
Configurator.initialize(new DefaultConfiguration());
|
||||||
|
Configurator.setRootLevel(Level.DEBUG);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue