<commit_before><commit_msg>[GLDP-71] Tests for operations around password attributes.<commit_after>package gldapo
import gldapo.schema.annotation.GldapoNamingAttribute

public class PasswordOperationsIntegrationTest extends AbstractGldapoIntegrationTest
{
    def schemaClasses = [PasswordOperationsIntegrationTestPerson]

    def newPerson(name, password) {
        new PasswordOperationsIntegrationTestPerson(
            cn: name,
            rdn: "cn=${name}",
            userPassword: password
        )
    }

    void testCreateWithNoPassword() {
        def p = newPerson("nopassword", null)
        p.save()
    }

    void testCreateWithPassword() {
        def p = newPerson("withpassword", "testpass")
        p.save()

        assertTrue(p.authenticate("testpass"))
        assertFalse(p.authenticate("nottherightpass"))
    }

    void testUpdatePassword() {
        importEntry(cn: "updatepassword", """
            objectclass: top
            objectclass: iNetOrgPerson
            sn: password1
        """)

        def p = PasswordOperationsIntegrationTestPerson.find(filter: "cn=updatepassword")

        p.userPassword = "<PASSWORD>"
        p.save()

        assertTrue(p.authenticate("<PASSWORD>"))
    }
}

class PasswordOperationsIntegrationTestPerson {
    Set<String> objectclass = ["top", "iNetOrgPerson"]
    String sn = "person"
    @GldapoNamingAttribute String cn
    String userPassword
}
{'fraction_non_alphanumeric': 0.09768095572733661, 'fraction_numerical': 0.0021082220660576245, 'mean_word_length': 2.977653631284916, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '2142343', 'n_tokens_mistral': 404, 'n_tokens_neox': 384, 'n_words': 77}