<commit_before>/*
 * Project: ironvas
 * Package: test.java.de.fhhannover.inform.trust.ironvas.converter
 * File:    FullEventUpdateConverterTest.java
 *
 * Copyright (C) 2011-2012 <NAME>
 * <NAME>adtweg 118, 30459 Hannover, Germany 
 *
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package de.fhhannover.inform.trust.ironvas.converter;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import org.junit.Before;
import org.junit.Test;
import org.w3c.dom.Document;

import de.fhhannover.inform.trust.ifmapj.identifier.IpAddress;
import de.fhhannover.inform.trust.ifmapj.messages.PublishDelete;
import de.fhhannover.inform.trust.ifmapj.messages.PublishUpdate;
import de.fhhannover.inform.trust.ironvas.Nvt;
import de.fhhannover.inform.trust.ironvas.RiskfactorLevel;
import de.fhhannover.inform.trust.ironvas.ThreatLevel;
import de.fhhannover.inform.trust.ironvas.Vulnerability;
import static org.junit.Assert.*;

public class FullEventUpdateConverterTest {
	
	private FullEventUpdateConverter converter;
	private SimpleDateFormat format;
	private Nvt nvt;
	private Vulnerability v;
	private Date date;
	
	
	@Before
	public void setUp() {
		String publisherId = "ironvas";
		String openVASId = "<EMAIL>";
		converter = new FullEventUpdateConverter(publisherId, openVASId);
		
		format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale.GERMANY);
		
		String nvt_oid = "1.3.6.1.4.1.25623.1.0.11229";
		String nvt_name = "phpinfo.php";
		float nvt_cvss_base = 0.0f;
		RiskfactorLevel riskfactor = RiskfactorLevel.Low;
		String cve = "NOCVE";
		String bid = "NOBID";
		
		String id = "f75673cf-c32a-467b-b495-1eb5fb2de100";
		date = new Date(0);
		String subnet = "192.168.7.7";
		String host = "192.168.7.7";
		String port = "http (80/tcp)";
		ThreatLevel threat = ThreatLevel.Medium;
		String description = "";
		
		nvt = new Nvt(nvt_oid, nvt_name, nvt_cvss_base, riskfactor, cve, bid);
		v = new Vulnerability(id, date, subnet, host, port, threat, description, nvt);
	}
	
	@Test
	public void testSingleUpdateMetadataSize() {
		PublishUpdate u = (PublishUpdate)converter.singleUpdate(v);
		assertEquals(1, u.getMetadata().size());
	}
	
	@Test
	public void testSingleUpdateName() {
		PublishUpdate u = (PublishUpdate)converter.singleUpdate(v);
		Document d = u.getMetadata().get(0);
		assertEquals("phpinfo.php",
				d.getElementsByTagName("name").item(0).getTextContent());
	}
	
	@Test
	public void testSingleUpdateDiscoveredTime() {
		PublishUpdate u = (PublishUpdate)converter.singleUpdate(v);
		Document d = u.getMetadata().get(0);
		assertEquals(format.format(date),
				d.getElementsByTagName("discovered-time").item(0).getTextContent());
	}
	
	@Test
	public void testSingleUpdateDiscovererId() {
		PublishUpdate u = (PublishUpdate)converter.singleUpdate(v);
		Document d = u.getMetadata().get(0);
		assertEquals("<EMAIL>",
				d.getElementsByTagName("discoverer-id").item(0).getTextContent());
	}
	
	@Test
	public void testSingleUpdateMagnitude() {
		PublishUpdate u = (PublishUpdate)converter.singleUpdate(v);
		Document d = u.getMetadata().get(0);
		assertEquals("0",
				d.getElementsByTagName("magnitude").item(0).getTextContent());
	}
	
	@Test
	public void testSingleUpdateConfidence() {
		PublishUpdate u = (PublishUpdate)converter.singleUpdate(v);
		Document d = u.getMetadata().get(0);
		assertEquals("0",
				d.getElementsByTagName("confidence").item(0).getTextContent());
	}
	
	@Test
	public void testSingleUpdateSignificance() {
		PublishUpdate u = (PublishUpdate)converter.singleUpdate(v);
		Document d = u.getMetadata().get(0);
		assertEquals("important",
				d.getElementsByTagName("significance").item(0).getTextContent());
	}
	
	@Test
	public void testSingleUpdateType() {
		PublishUpdate u = (PublishUpdate)converter.singleUpdate(v);
		Document d = u.getMetadata().get(0);
		assertEquals("cve",
				d.getElementsByTagName("type").item(0).getTextContent());
	}
	
	@Test
	public void testSingleUpdateOtherTypeDefinition() {
		PublishUpdate u = (PublishUpdate)converter.singleUpdate(v);
		Document d = u.getMetadata().get(0);
		assertEquals("",
				d.getElementsByTagName("other-type-definition").item(0).getTextContent());
	}
	
	@Test
	public void testSingleUpdateInformation() {
		PublishUpdate u = (PublishUpdate)converter.singleUpdate(v);
		Document d = u.getMetadata().get(0);
		assertEquals("",
				d.getElementsByTagName("information").item(0).getTextContent());
	}
	
	@Test
	public void testSingleUpdateVulnerabilityUri() {
		PublishUpdate u = (PublishUpdate)converter.singleUpdate(v);
		Document d = u.getMetadata().get(0);
		assertEquals("NOCVE",
				d.getElementsByTagName("vulnerability-uri").item(0).getTextContent());
	}
	
	@Test
	public void testSingleDeleteIpAddress() {
		PublishDelete d = converter.singleDelete(v);
		assertEquals("192.168.7.7", ((IpAddress)d.getIdentifier1()).getValue());
	}
	
	@Test
	public void testSingleDeleteFilter() {
		PublishDelete d = converter.singleDelete(v);
		String filter = "meta:event[@ifmap-publisher-id='ironvas' "+
				"and name='phpinfo.php' "+
				"and discovered-time='1970-01-01T01:00:00+0100' "+
				"and discoverer-id='<EMAIL>' "+
				"and magnitude='0' " +
				"and confidence='0' " +
				"and significance='important' " +
				"and type='cve' "+
				"and other-type-definition='' " +
				"and information='' "+
				"and vulnerability-uri='NOCVE']";
		assertEquals(filter, d.getFilter());
	}
}
<commit_msg>ironvas: align tests to new converter<commit_after>/*
 * Project: ironvas
 * Package: test.java.de.fhhannover.inform.trust.ironvas.converter
 * File:    FullEventUpdateConverterTest.java
 *
 * Copyright (C) 2011-2012 <NAME>
 * Ricklinger Stadtweg 118, 30459 Hannover, Germany 
 *
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package de.fhhannover.inform.trust.ironvas.converter;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import org.junit.Before;
import org.junit.Test;
import org.w3c.dom.Document;

import de.fhhannover.inform.trust.ifmapj.identifier.IpAddress;
import de.fhhannover.inform.trust.ifmapj.messages.PublishDelete;
import de.fhhannover.inform.trust.ifmapj.messages.PublishUpdate;
import de.fhhannover.inform.trust.ironvas.Nvt;
import de.fhhannover.inform.trust.ironvas.RiskfactorLevel;
import de.fhhannover.inform.trust.ironvas.ThreatLevel;
import de.fhhannover.inform.trust.ironvas.Vulnerability;
import static org.junit.Assert.*;

public class FullEventUpdateConverterTest {
	
	private FullEventUpdateConverter converter;
	private SimpleDateFormat format;
	private Nvt nvt;
	private Vulnerability v;
	private Date date;
	
	
	@Before
	public void setUp() {
		String publisherId = "ironvas";
		String openVASId = "<EMAIL>";
		converter = new FullEventUpdateConverter(publisherId, openVASId);
		
		format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale.GERMANY);
		
		String nvt_oid = "1.3.6.1.4.1.25623.1.0.11229";
		String nvt_name = "phpinfo.php";
		float nvt_cvss_base = 0.0f;
		RiskfactorLevel riskfactor = RiskfactorLevel.Low;
		String cve = "NOCVE";
		String bid = "NOBID";
		
		String id = "f75673cf-c32a-467b-b495-1eb5fb2de100";
		date = new Date(0);
		String subnet = "192.168.7.7";
		String host = "192.168.7.7";
		String port = "http (80/tcp)";
		ThreatLevel threat = ThreatLevel.Medium;
		String description = "";
		
		nvt = new Nvt(nvt_oid, nvt_name, nvt_cvss_base, riskfactor, cve, bid);
		v = new Vulnerability(id, date, subnet, host, port, threat, description, nvt);
	}
	
	@Test
	public void testSingleUpdateMetadataSize() {
		PublishUpdate u = (PublishUpdate)converter.singleUpdate(v);
		assertEquals(1, u.getMetadata().size());
	}
	
	@Test
	public void testSingleUpdateName() {
		PublishUpdate u = (PublishUpdate)converter.singleUpdate(v);
		Document d = u.getMetadata().get(0);
		assertEquals("phpinfo.php:f75673cf-c32a-467b-b495-1eb5fb2de100",
				d.getElementsByTagName("name").item(0).getTextContent());
	}
	
	@Test
	public void testSingleUpdateDiscoveredTime() {
		PublishUpdate u = (PublishUpdate)converter.singleUpdate(v);
		Document d = u.getMetadata().get(0);
		assertEquals(format.format(date),
				d.getElementsByTagName("discovered-time").item(0).getTextContent());
	}
	
	@Test
	public void testSingleUpdateDiscovererId() {
		PublishUpdate u = (PublishUpdate)converter.singleUpdate(v);
		Document d = u.getMetadata().get(0);
		assertEquals("<EMAIL>",
				d.getElementsByTagName("discoverer-id").item(0).getTextContent());
	}
	
	@Test
	public void testSingleUpdateMagnitude() {
		PublishUpdate u = (PublishUpdate)converter.singleUpdate(v);
		Document d = u.getMetadata().get(0);
		assertEquals("0",
				d.getElementsByTagName("magnitude").item(0).getTextContent());
	}
	
	@Test
	public void testSingleUpdateConfidence() {
		PublishUpdate u = (PublishUpdate)converter.singleUpdate(v);
		Document d = u.getMetadata().get(0);
		assertEquals("0",
				d.getElementsByTagName("confidence").item(0).getTextContent());
	}
	
	@Test
	public void testSingleUpdateSignificance() {
		PublishUpdate u = (PublishUpdate)converter.singleUpdate(v);
		Document d = u.getMetadata().get(0);
		assertEquals("important",
				d.getElementsByTagName("significance").item(0).getTextContent());
	}
	
	@Test
	public void testSingleUpdateType() {
		PublishUpdate u = (PublishUpdate)converter.singleUpdate(v);
		Document d = u.getMetadata().get(0);
		assertEquals("cve",
				d.getElementsByTagName("type").item(0).getTextContent());
	}
	
	@Test
	public void testSingleUpdateOtherTypeDefinition() {
		PublishUpdate u = (PublishUpdate)converter.singleUpdate(v);
		Document d = u.getMetadata().get(0);
		assertEquals("",
				d.getElementsByTagName("other-type-definition").item(0).getTextContent());
	}
	
	@Test
	public void testSingleUpdateInformation() {
		PublishUpdate u = (PublishUpdate)converter.singleUpdate(v);
		Document d = u.getMetadata().get(0);
		assertEquals("",
				d.getElementsByTagName("information").item(0).getTextContent());
	}
	
	@Test
	public void testSingleUpdateVulnerabilityUri() {
		PublishUpdate u = (PublishUpdate)converter.singleUpdate(v);
		Document d = u.getMetadata().get(0);
		assertEquals("NOCVE",
				d.getElementsByTagName("vulnerability-uri").item(0).getTextContent());
	}
	
	@Test
	public void testSingleDeleteIpAddress() {
		PublishDelete d = converter.singleDelete(v);
		assertEquals("192.168.7.7", ((IpAddress)d.getIdentifier1()).getValue());
	}
	
	@Test
	public void testSingleDeleteFilter() {
		PublishDelete d = converter.singleDelete(v);
		String filter = "meta:event[@ifmap-publisher-id='ironvas' "+
				"and name='phpinfo.php:f75673cf-c32a-467b-b495-1eb5fb2de100']";
		assertEquals(filter, d.getFilter());
	}
}

{'fraction_non_alphanumeric': 0.13332761725113607, 'fraction_numerical': 0.024007545228500387, 'mean_word_length': 4.9662404092071615, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 10, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3025771', 'n_tokens_mistral': 4301, 'n_tokens_neox': 3817, 'n_words': 764}