package com.onelogin.saml2.test.settings;

import static org.junit.Assert.assertEquals;

import java.io.FileNotFoundException;
import java.io.IOException;

import org.junit.Test;

import com.onelogin.saml2.settings.Saml2Settings;
import com.onelogin.saml2.settings.SettingsBuilder;
import com.onelogin.saml2.util.Util;

public class SettingBuilderTest {

	// TODO create file.properties with all properties

	@Test
	public void loadFromFileCertString() throws Exception {
		Saml2Settings setting = new SettingsBuilder().fromFile("config/config.certstring.properties").build();

		checkSettings(setting);
	}

	private void checkSettings(Saml2Settings setting) throws Exception {
		assertEquals(setting.isDebugActive(), false);
		assertEquals(setting.isStrict(), false);
		assertEquals(setting.getSpEntityId(), "http://localhost:8080/java-saml-jspsample/metadata.jsp");
		assertEquals(setting.getSpAssertionConsumerServiceUrl().toString(),
				"http://localhost:8080/java-saml-jspsample/acs.jsp");
		assertEquals(setting.getSpAssertionConsumerServiceBinding(), "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST");
		assertEquals(setting.getSpSingleLogoutServiceUrl().toString(),
				"http://localhost:8080/java-saml-jspsample/sls.jsp");
		assertEquals(setting.getSpSingleLogoutServiceBinding(), "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect");

		assertEquals(setting.getSpNameIDFormat(), "urn:oasis:names:tc:SAML:2.0:nameid-format:unspecified");

		assertEquals(setting.getIdpEntityId(), "");
		assertEquals(setting.getIdpSingleSignOnServiceUrl().toString(),
				"http://pitbulk.no-ip.org/simplesaml/saml2/idp/SSOService.php");
		assertEquals(setting.getIdpSingleSignOnServiceBinding(), "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect");
		assertEquals(setting.getIdpSingleLogoutServiceUrl().toString(),
				"http://pitbulk.no-ip.org/simplesaml/saml2/idp/logout.php");
		assertEquals(setting.getIdpSingleLogoutServiceBinding(), "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect");
		assertEquals(setting.getIdpx509cert(), Util.loadCert(Util.getFileAsString("certs/certificate1")));

	}

	/*
	@Test
	public void loadFromFileCertFile() throws IOException {
		new SettingsBuilder().fromFile("config/config.certfile.properties").build();
	}
	*/

	@Test(expected = FileNotFoundException.class)
	public void loadFromFileNotExist() throws IOException {
		new SettingsBuilder().fromFile("config/config.notfound.properties").build();
	}

	@Test
	public void loadFromFileEmpty() throws IOException {
		new SettingsBuilder().fromFile("config/config.empty.properties").build();
	}
}

@@ -1485,16 +1485,39 @@
 yId(), %22
+http://idp.example.com/
 %22);%0A%09%09as
@@ -1594,46 +1594,23 @@
 p://
-pitbulk.no-ip.org/simplesaml/saml2/idp
+idp.example.com
 /SSO
@@ -1820,53 +1820,43 @@
 p://
-pitbulk.no-ip.org/simplesaml/saml2/idp/logout
+idp.example.com/SingleLogoutService
 .php

Update SettingBuilderTest.checkSettings to match config.certstring.properties