Skip to content

Add a custom schema to SlapdObject with a slapadd method? #373

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
azmeuk opened this issue Aug 18, 2020 · 3 comments · Fixed by #382
Closed

Add a custom schema to SlapdObject with a slapadd method? #373

azmeuk opened this issue Aug 18, 2020 · 3 comments · Fixed by #382

Comments

@azmeuk
Copy link
Contributor

azmeuk commented Aug 18, 2020

Operating system: Archlinux
Python version: 3.8.5
python-ldap version: 3.3.0

I wrote a custom schema and I would like to write some tests using this schema.

I can manage to do this by copying or linking my schema files in SlapdObject.SCHEMA_DIR before the process is launched. However this is not convenient at all (see next comment).

The ldapadd command cannot add schemas:

RuntimeError: ['/usr/bin/ldapadd', '-H', 'ldapi://%2Fhome%2Feloi%2Fdev%2Fyaal%2Foidc-ldap-bridge%2Fpython-ldap-test-52629%2Fldapi', '-Y', 'EXTERNAL', '-Q'] process failed:
b'adding new entry "cn=oauth,cn=schema,cn=config"\n\n'
b'ldap_add: Insufficient access (50)\n'

However, the slapadd command could. I suggest to implement a SlapdObject.slapadd method, similar to SlapdObject.ldapadd. This would allow to call slapadd -l myschema.ldif -n0 (-n0 being an option, that could be used to add the schema in the config database). This way, one could add a schema to the slapd server test after it is started.

If ldapadd seems too much, maybe we can just find a mechanism to simply add custom schemas by configuring or passing parameters to SlapdObject?

If you are ok with this, I can provide a patch.
What do you think?

@azmeuk azmeuk changed the title Add a custom schema to SlapdObject Add a custom schema to SlapdObject with a SlapdObject.slapadd method? Aug 18, 2020
@azmeuk azmeuk changed the title Add a custom schema to SlapdObject with a SlapdObject.slapadd method? Add a custom schema to SlapdObject with a slapadd method? Aug 18, 2020
@azmeuk
Copy link
Contributor Author

azmeuk commented Aug 18, 2020

For the record, here is how I add custom schema now:

class CustomSlapdObject(slapdtest.SlapdObject):
    custom_schema_files = ("my_custom.schema",)
    custom_schema_dir = "/path/to/somewhere"

    def _ln_schema_files(self, *args, **kwargs):
        super()._ln_schema_files(*args, **kwargs)
        super()._ln_schema_files(self.custom_schema_files, self.custom_schema_dir)

    def gen_config(self):
        previous = self.openldap_schema_files
        self.openldap_schema_files += self.custom_schema_files
        config = super().gen_config()
        self.openldap_schema_files = previous
        return config

@encukou
Copy link
Member

encukou commented Sep 1, 2020

That generally sounds reasonable.
What kind of tests are you planning to write?

@azmeuk
Copy link
Contributor Author

azmeuk commented Sep 1, 2020

Well I suppose I would write a test for my usecase. That would be use slapadd to add a custom schema, and then confirm that then create an object in the database defined in this schema.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants