<commit_before>package gov.nih.nci.cagrid.gums.idp;

import gov.nih.nci.cagrid.gums.ca.CertificateAuthority;
import gov.nih.nci.cagrid.gums.common.Database;
import gov.nih.nci.cagrid.gums.common.FaultUtil;
import gov.nih.nci.cagrid.gums.idp.bean.Application;
import gov.nih.nci.cagrid.gums.idp.bean.BasicAuthCredential;
import gov.nih.nci.cagrid.gums.idp.bean.CountryCode;
import gov.nih.nci.cagrid.gums.idp.bean.IdPUser;
import gov.nih.nci.cagrid.gums.idp.bean.IdPUserFilter;
import gov.nih.nci.cagrid.gums.idp.bean.IdPUserRole;
import gov.nih.nci.cagrid.gums.idp.bean.IdPUserStatus;
import gov.nih.nci.cagrid.gums.idp.bean.StateCode;
import gov.nih.nci.cagrid.gums.test.TestResourceManager;
import gov.nih.nci.cagrid.gums.test.TestUtils;

import java.io.File;
import java.util.Iterator;

import junit.framework.TestCase;

import org.opensaml.SAMLAssertion;
import org.opensaml.SAMLAttribute;
import org.opensaml.SAMLAttributeStatement;
import org.opensaml.SAMLAuthenticationStatement;
import org.opensaml.SAMLStatement;

/**
 * @author <A href="mailto:<EMAIL>"><NAME> </A>
 * @author <A href="mailto:<EMAIL>"><NAME> </A>
 * @author <A href="mailto:<EMAIL>"><NAME> </A>
 * @version $Id: ArgumentManagerTable.java,v 1.2 2004/10/15 16:35:16 langella
 *          Exp $
 */
public class TestIdentityProvider extends TestCase {

	private IdPConfiguration conf;

	private Database db;

	private CertificateAuthority ca;

	public static String IDP_CONFIG = "resources" + File.separator
			+ "general-test" + File.separator + "idp-config.xml";

	private int count = 0;

	public void testAutomaticRegistration() {
		try {

			IdentityProvider idp = new IdentityProvider(conf, db, ca);
			conf.setRegistrationPolicy(new AutomaticRegistrationPolicy());
			assertEquals(AutomaticRegistrationPolicy.class.getName(), conf
					.getRegistrationPolicy().getClass().getName());
			Application a = createApplication();
			idp.register(a);
			BasicAuthCredential cred = getAdminCreds();
			IdPUserFilter uf = new IdPUserFilter();
			uf.setUserId(a.getUserId());
			IdPUser[] users = idp.findUsers(cred, uf);
			assertEquals(1, users.length);
			assertEquals(IdPUserStatus.Active, users[0].getStatus());
			assertEquals(IdPUserRole.Non_Administrator, users[0].getRole());
		} catch (Exception e) {
			FaultUtil.printFault(e);
			assertTrue(false);
		}
	}

	public void testManualRegistration() {
		try {
			IdentityProvider idp = new IdentityProvider(conf, db, ca);
			conf.setRegistrationPolicy(new ManualRegistrationPolicy());
			assertEquals(ManualRegistrationPolicy.class.getName(), conf
					.getRegistrationPolicy().getClass().getName());
			Application a = createApplication();
			idp.register(a);
			BasicAuthCredential cred = getAdminCreds();
			IdPUserFilter uf = new IdPUserFilter();
			uf.setUserId(a.getUserId());
			IdPUser[] users = idp.findUsers(cred, uf);
			assertEquals(1, users.length);
			assertEquals(IdPUserStatus.Pending, users[0].getStatus());
			assertEquals(IdPUserRole.Non_Administrator, users[0].getRole());
			users[0].setStatus(IdPUserStatus.Active);
			idp.updateUser(cred, users[0]);
			users = idp.findUsers(cred, uf);
			assertEquals(1, users.length);
			assertEquals(IdPUserStatus.Active, users[0].getStatus());
		} catch (Exception e) {
			FaultUtil.printFault(e);
			assertTrue(false);
		}
	}

	public void testMultipleUsers() {
		try {
			IdentityProvider idp = new IdentityProvider(conf, db, ca);
			conf.setRegistrationPolicy(new ManualRegistrationPolicy());
			assertEquals(ManualRegistrationPolicy.class.getName(), conf
					.getRegistrationPolicy().getClass().getName());
			BasicAuthCredential cred = getAdminCreds();
			for (int i = 0; i < 10; i++) {
				Application a = createApplication();
				idp.register(a);

				IdPUserFilter uf = new IdPUserFilter();
				uf.setUserId(a.getUserId());
				IdPUser[] users = idp.findUsers(cred, uf);
				assertEquals(1, users.length);
				assertEquals(IdPUserStatus.Pending, users[0].getStatus());
				assertEquals(IdPUserRole.Non_Administrator, users[0].getRole());
				users[0].setStatus(IdPUserStatus.Active);
				idp.updateUser(cred, users[0]);
				users = idp.findUsers(cred, uf);
				assertEquals(1, users.length);
				assertEquals(IdPUserStatus.Active, users[0].getStatus());
				uf.setUserId("user");
				users = idp.findUsers(cred, uf);
				assertEquals(i + 1, users.length);
				BasicAuthCredential auth = new BasicAuthCredential();
				auth.setUserId(a.getUserId());
				auth.setPassword(a.<PASSWORD>());
				org.opensaml.SAMLAssertion saml = idp.authenticate(auth);
				assertNotNull(saml);
				this.verifySAMLAssertion(saml,idp,a);

			}

			IdPUserFilter uf = new IdPUserFilter();
			IdPUser[] users = idp.findUsers(cred, uf);
			assertEquals(11, users.length);
			for (int i = 0; i < 10; i++) {
				IdPUserFilter f = new IdPUserFilter();
				f.setUserId(users[i].getUserId());
				IdPUser[] us = idp.findUsers(cred, f);
				assertEquals(1, us.length);
				us[0].setFirstName("<NAME>");
				idp.updateUser(cred, us[0]);
				IdPUser[] us2 = idp.findUsers(cred, f);<commit_msg>*** empty log message ***<commit_after>package gov.nih.nci.cagrid.gums.idp;

import gov.nih.nci.cagrid.gums.ca.CertificateAuthority;
import gov.nih.nci.cagrid.gums.common.Database;
import gov.nih.nci.cagrid.gums.common.FaultUtil;
import gov.nih.nci.cagrid.gums.idp.bean.Application;
import gov.nih.nci.cagrid.gums.idp.bean.BasicAuthCredential;
import gov.nih.nci.cagrid.gums.idp.bean.CountryCode;
import gov.nih.nci.cagrid.gums.idp.bean.IdPUser;
import gov.nih.nci.cagrid.gums.idp.bean.IdPUserFilter;
import gov.nih.nci.cagrid.gums.idp.bean.IdPUserRole;
import gov.nih.nci.cagrid.gums.idp.bean.IdPUserStatus;
import gov.nih.nci.cagrid.gums.idp.bean.StateCode;
import gov.nih.nci.cagrid.gums.test.TestResourceManager;
import gov.nih.nci.cagrid.gums.test.TestUtils;

import java.io.File;
import java.util.Iterator;

import junit.framework.TestCase;

import org.opensaml.SAMLAssertion;
import org.opensaml.SAMLAttribute;
import org.opensaml.SAMLAttributeStatement;
import org.opensaml.SAMLAuthenticationStatement;
import org.opensaml.SAMLStatement;

/**
 * @author <A href="mailto:<EMAIL>"><NAME> </A>
 * @author <A href="mailto:<EMAIL>"><NAME> </A>
 * @author <A href="mailto:<EMAIL>"><NAME> </A>
 * @version $Id: ArgumentManagerTable.java,v 1.2 2004/10/15 16:35:16 langella
 *          Exp $
 */
public class TestIdentityProvider extends TestCase {

	private IdPConfiguration conf;

	private Database db;

	private CertificateAuthority ca;

	public static String IDP_CONFIG = "resources" + File.separator
			+ "general-test" + File.separator + "idp-config.xml";

	private int count = 0;

	public void testAutomaticRegistration() {
		try {

			IdentityProvider idp = new IdentityProvider(conf, db, ca);
			conf.setRegistrationPolicy(new AutomaticRegistrationPolicy());
			assertEquals(AutomaticRegistrationPolicy.class.getName(), conf
					.getRegistrationPolicy().getClass().getName());
			Application a = createApplication();
			idp.register(a);
			BasicAuthCredential cred = getAdminCreds();
			IdPUserFilter uf = new IdPUserFilter();
			uf.setUserId(a.getUserId());
			IdPUser[] users = idp.findUsers(cred, uf);
			assertEquals(1, users.length);
			assertEquals(IdPUserStatus.Active, users[0].getStatus());
			assertEquals(IdPUserRole.Non_Administrator, users[0].getRole());
		} catch (Exception e) {
			FaultUtil.printFault(e);
			assertTrue(false);
		}
	}

	public void testManualRegistration() {
		try {
			IdentityProvider idp = new IdentityProvider(conf, db, ca);
			conf.setRegistrationPolicy(new ManualRegistrationPolicy());
			assertEquals(ManualRegistrationPolicy.class.getName(), conf
					.getRegistrationPolicy().getClass().getName());
			Application a = createApplication();
			idp.register(a);
			BasicAuthCredential cred = getAdminCreds();
			IdPUserFilter uf = new IdPUserFilter();
			uf.setUserId(a.getUserId());
			IdPUser[] users = idp.findUsers(cred, uf);
			assertEquals(1, users.length);
			assertEquals(IdPUserStatus.Pending, users[0].getStatus());
			assertEquals(IdPUserRole.Non_Administrator, users[0].getRole());
			users[0].setStatus(IdPUserStatus.Active);
			idp.updateUser(cred, users[0]);
			users = idp.findUsers(cred, uf);
			assertEquals(1, users.length);
			assertEquals(IdPUserStatus.Active, users[0].getStatus());
		} catch (Exception e) {
			FaultUtil.printFault(e);
			assertTrue(false);
		}
	}

	public void testMultipleUsers() {
		try {
			IdentityProvider idp = new IdentityProvider(conf, db, ca);
			conf.setRegistrationPolicy(new ManualRegistrationPolicy());
			assertEquals(ManualRegistrationPolicy.class.getName(), conf
					.getRegistrationPolicy().getClass().getName());
			BasicAuthCredential cred = getAdminCreds();
			for (int i = 0; i < 10; i++) {
				Application a = createApplication();
				idp.register(a);

				IdPUserFilter uf = new IdPUserFilter();
				uf.setUserId(a.getUserId());
				IdPUser[] users = idp.findUsers(cred, uf);
				assertEquals(1, users.length);
				assertEquals(IdPUserStatus.Pending, users[0].getStatus());
				assertEquals(IdPUserRole.Non_Administrator, users[0].getRole());
				users[0].setStatus(IdPUserStatus.Active);
				idp.updateUser(cred, users[0]);
				users = idp.findUsers(cred, uf);
				assertEquals(1, users.length);
				assertEquals(IdPUserStatus.Active, users[0].getStatus());
				uf.setUserId("user");
				users = idp.findUsers(cred, uf);
				assertEquals(i + 1, users.length);
				BasicAuthCredential auth = new BasicAuthCredential();
				auth.setUserId(a.getUserId());
				auth.setPassword(<PASSWORD>());
				org.opensaml.SAMLAssertion saml = idp.authenticate(auth);
				assertNotNull(saml);
				this.verifySAMLAssertion(saml,idp,a);
			}

			IdPUserFilter uf = new IdPUserFilter();
			IdPUser[] users = idp.findUsers(cred, uf);
			assertEquals(11, users.length);
			for (int i = 0; i < 10; i++) {
				IdPUserFilter f = new IdPUserFilter();
				f.setUserId(users[i].getUserId());
				IdPUser[] us = idp.findUsers(cred, f);
				assertEquals(1, us.length);
				us[0].setFirstName("<NAME>");
				idp.updateUser(cred, us[0]);
				IdPUser[] us2 = idp.findUsers(cred, f);
{'fraction_non_alphanumeric': 0.14322427597113768, 'fraction_numerical': 0.00929129188494613, 'mean_word_length': 4.77841233580811, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, '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': '5715628', 'n_tokens_mistral': 3911, 'n_tokens_neox': 3472, 'n_words': 587}