Esempio n. 1
0
def test_dsidm_user_modify(topology_st, create_test_user):
    """ Test dsidm user modify add, replace, delete option

    :id: 7a27be19-1a63-44d0-b11b-f877e06e1a9b
    :setup: Standalone instance
    :steps:
         1. Run dsidm user modify replace cn value
         2. Run dsidm user modify add telephoneNumber attribute to user
         3. Run dsidm user modify delete for telephoneNumber attribute
    :expectedresults:
         1. cn value is replaced with new name
         2. telephoneNumber attribute is present
         3. telephoneNumber attribute is deleted
    """

    standalone = topology_st.standalone
    users = nsUserAccounts(standalone, DEFAULT_SUFFIX)
    test_user = users.get('test_user_1000')
    output = 'Successfully modified {}'.format(test_user.dn)

    args = FakeArgs()
    args.selector = 'test_user_1000'
    args.changes = ['replace:cn:test']

    log.info('Test dsidm user modify replace')
    modify(standalone,
           DEFAULT_SUFFIX,
           topology_st.logcap.log,
           args,
           warn=False)
    check_value_in_log_and_reset(topology_st, check_value=output)

    log.info('Test dsidm user modify add')
    args.changes = ['add:telephoneNumber:1234567890']
    modify(standalone,
           DEFAULT_SUFFIX,
           topology_st.logcap.log,
           args,
           warn=False)
    check_value_in_log_and_reset(topology_st, check_value=output)
    assert test_user.present('telephoneNumber', '1234567890')

    log.info('Test dsidm user modify delete')
    args.changes = ['delete:telephoneNumber:1234567890']
    modify(standalone,
           DEFAULT_SUFFIX,
           topology_st.logcap.log,
           args,
           warn=False)
    check_value_in_log_and_reset(topology_st, check_value=output)
    assert not test_user.present('telephoneNumber', '1234567890')
def test_dsidm_service_modify(topology_st, create_test_service):
    """ Test dsidm service modify add, replace, delete option

    :id: 4023ef22-51e1-11ec-93c5-3497f624ea11
    :setup: Standalone instance
    :steps:
         1. Run dsidm service modify replace description value
         2. Run dsidm service modify add seeAlso attribute to service
         3. Run dsidm service modify delete for seeAlso attribute
    :expectedresults:
         1. description value is replaced with new text
         2. seeAlso attribute is present
         3. seeAlso attribute is deleted
    """

    standalone = topology_st.standalone
    services = ServiceAccounts(standalone, DEFAULT_SUFFIX)
    test_service = services.get('test_service')
    output = f'Successfully modified {test_service.dn}'

    args = FakeArgs()
    args.selector = 'test_service'
    args.changes = ['replace:description:Test Service Modified']

    log.info('Test dsidm service modify replace')
    modify(standalone,
           DEFAULT_SUFFIX,
           topology_st.logcap.log,
           args,
           warn=False)
    check_value_in_log_and_reset(topology_st, check_value=output)

    log.info('Test dsidm service modify add')
    args.changes = [f'add:seeAlso:ou=services,{DEFAULT_SUFFIX}']
    modify(standalone,
           DEFAULT_SUFFIX,
           topology_st.logcap.log,
           args,
           warn=False)
    check_value_in_log_and_reset(topology_st, check_value=output)
    assert test_service.present('seeAlso', f'ou=services,{DEFAULT_SUFFIX}')

    log.info('Test dsidm service modify delete')
    args.changes = [f'delete:seeAlso:ou=services,{DEFAULT_SUFFIX}']
    modify(standalone,
           DEFAULT_SUFFIX,
           topology_st.logcap.log,
           args,
           warn=False)
    check_value_in_log_and_reset(topology_st, check_value=output)
    assert not test_service.present('seeAlso', f'ou=services,{DEFAULT_SUFFIX}')
def test_user_modify(topology):
    be_args = FakeArgs()

    be_args.be_name = 'userRoot'
    be_args.suffix = DEFAULT_SUFFIX
    be_args.parent_suffix = None
    be_args.create_entries = False
    backend_create(topology.standalone, None, topology.logcap.log, be_args)

    # And add the skeleton objects.
    init_args = FakeArgs()
    init_args.version = INSTALL_LATEST_CONFIG
    initialise(topology.standalone, DEFAULT_SUFFIX, topology.logcap.log, init_args)

    # Check that our modify parser works. Modify statements are such as:
    # "add:attr:value". Replace is the exception as "replace:attr:old:new"

    # Check bad syntax
    modify_args = FakeArgs()
    modify_args.selector = "demo_user"
    modify_args.changes = ["tnaohtnsuahtnsouhtns"]

    with pytest.raises(ValueError):
        modify(topology.standalone, DEFAULT_SUFFIX, topology.logcap.log, modify_args)

    modify_args.changes = ["add:attr:"]
    with pytest.raises(ValueError):
        modify(topology.standalone, DEFAULT_SUFFIX, topology.logcap.log, modify_args)

    modify_args.changes = ["add:attr"]
    with pytest.raises(ValueError):
        modify(topology.standalone, DEFAULT_SUFFIX, topology.logcap.log, modify_args)

    modify_args.changes = ["replace::"]
    with pytest.raises(ValueError):
        modify(topology.standalone, DEFAULT_SUFFIX, topology.logcap.log, modify_args)

    modify_args.changes = ["replace:attr::new"]
    with pytest.raises(ValueError):
        modify(topology.standalone, DEFAULT_SUFFIX, topology.logcap.log, modify_args)

    modify_args.changes = ["delete:attr:old:new"]
    with pytest.raises(ValueError):
        modify(topology.standalone, DEFAULT_SUFFIX, topology.logcap.log, modify_args)

    # Check that even a single bad value causes error
    modify_args.changes = ["add:description:goodvalue", "add:attr:"]
    with pytest.raises(ValueError):
        modify(topology.standalone, DEFAULT_SUFFIX, topology.logcap.log, modify_args)

    # check good syntax
    modify_args.changes = ["add:description:testvalue"]
    modify(topology.standalone, DEFAULT_SUFFIX, topology.logcap.log, modify_args)

    modify_args.changes = ["replace:description:newvalue"]
    modify(topology.standalone, DEFAULT_SUFFIX, topology.logcap.log, modify_args)

    modify_args.changes = ["delete:description:newvalue"]
    modify(topology.standalone, DEFAULT_SUFFIX, topology.logcap.log, modify_args)

    modify_args.changes = ["add:description:testvalue"]
    modify(topology.standalone, DEFAULT_SUFFIX, topology.logcap.log, modify_args)

    modify_args.changes = ["delete:description:"]
    modify(topology.standalone, DEFAULT_SUFFIX, topology.logcap.log, modify_args)

    # check mixed type, with multiple actions

    modify_args.changes = ["add:objectclass:nsMemberOf", "add:description:anothervalue"]
    modify(topology.standalone, DEFAULT_SUFFIX, topology.logcap.log, modify_args)