def query_attributetype(inst, basedn, log, args): log = log.getChild('query_attributetype') schema = Schema(inst) # Need the query type attr = _get_arg(args.name, msg="Enter attribute to query") if args.json: print(dump_json(schema.query_attributetype(attr, json=args.json), indent=4)) else: attributetype, must, may = schema.query_attributetype(attr, json=args.json) print(attributetype) print("") print("MUST") for oc in must: print(oc) print("") print("MAY") for oc in may: print(oc)
def test_x_origin(topo): """ Test that the various forms of X-ORIGIN are handled correctly :id: 995acc60-243b-45b0-9c1c-12bbe6a2882d :setup: Standalone Instance :steps: 1. Create schema file with specific/unique formats for X-ORIGIN 2. Reload the schema file (schema reload task) 3. List all attributes without error 4. Confirm the expected results :expectedresults: 1. Success 2. Success 3. Success 4. Success """ # Create a custom schema file so we can tests specific formats schema_file_name = topo.standalone.schemadir + '/98test.ldif' schema_file = open(schema_file_name, "w") testschema = ( "dn: cn=schema\n" + "attributetypes: ( 8.9.10.11.12.13.16 NAME 'testattr' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 X-ORIGIN 'USER_DEFINED' )\n" + "attributetypes: ( 8.9.10.11.12.13.17 NAME 'testattrtwo' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 X-ORIGIN ( 'USER_DEFINED' 'should be not ignored!!' ) )\n" ) schema_file.write(testschema) schema_file.close() # Reload the schema myschema = Schema(topo.standalone) task = myschema.reload() assert task.exists() task.wait() assert task.get_exit_code() == 0 # Now search attrs and make sure there are no errors myschema.get_attributetypes() myschema.get_objectclasses() # Check we have X-ORIGIN as expected assert " 'USER_DEFINED' " in str(myschema.query_attributetype("testattr")) assert " 'USER_DEFINED' " in str( myschema.query_attributetype("testattrtwo"))
def test_origins_with_extra_parenthesis(topo): """Test the custom schema with extra parenthesis in X-ORIGIN can be parsed into JSON :id: 4230f83b-0dc3-4bc4-a7a8-5ab0826a4f05 :setup: Standalone Instance :steps: 1. Add attribute with X-ORIGIN that contains extra parenthesis 2. Querying for that attribute with JSON flag :expectedresults: 1. Success 2. Success """ ATTR_NAME = 'testAttribute' X_ORG_VAL = 'test (TEST)' schema = Schema(topo.standalone) # Add new attribute parameters = { 'names': [ATTR_NAME], 'oid': '1.1.1.1.1.1.1.22222', 'desc': 'Test extra parenthesis in X-ORIGIN', 'x_origin': X_ORG_VAL, 'syntax': '1.3.6.1.4.1.1466.115.121.1.15', 'syntax_len': None, 'x_ordered': None, 'collective': None, 'obsolete': None, 'single_value': None, 'no_user_mod': None, 'equality': None, 'substr': None, 'ordering': None, 'usage': None, 'sup': None } schema.add_attributetype(parameters) # Search for attribute with JSON option attr_result = schema.query_attributetype(ATTR_NAME, json=True) # Verify the x-origin value is correct assert attr_result['at']['x_origin'][0] == X_ORG_VAL