tests/integration/integration_setup.py
def init_server(dbconn) -> dict:
	'''Adds basic data to the database as if setupconfig had been run. It also rotates the org 
	keycard so that there are two entries. Returns data needed for tests, such as the keys'''
	
	# Start off by generating the org's root keycard entry and add to the database

	cur = dbconn.cursor()
	card = keycard.Keycard('Organization')
	
	root_entry = keycard.OrgEntry()
	root_entry.set_fields({
		'Name':'Example, Inc.',
		'Contact-Admin':'c590b44c-798d-4055-8d72-725a7942f3f6/acme.com',
		'Language':'en',
		'Domain':'example.com',
		'Primary-Verification-Key':'ED25519:r#r*RiXIN-0n)BzP3bv`LA&t4LFEQNF0Q@$N~RF*',
		'Encryption-Key':'CURVE25519:SNhj2K`hgBd8>G>lW$!pXiM7S-B!Fbd9jT2&{{Az'
	})

	initial_ovkey = CryptoString(r'ED25519:r#r*RiXIN-0n)BzP3bv`LA&t4LFEQNF0Q@$N~RF*')
	initial_oskey = CryptoString(r'ED25519:{UNQmjYhz<(-ikOBYoEQpXPt<irxUF*nq25PoW=_')
	initial_ovhash = CryptoString(r'BLAKE2B-256:ag29av@TUvh-V5KaB2l}H=m?|w`}dvkS1S1&{cMo')

	initial_epubkey = CryptoString(r'CURVE25519:SNhj2K`hgBd8>G>lW$!pXiM7S-B!Fbd9jT2&{{Az')
	initial_eprivkey = CryptoString(r'CURVE25519:WSHgOhi+bg=<bO^4UoJGF-z9`+TBN{ds?7RZ;w3o')
	initial_epubhash = CryptoString(r'BLAKE2B-256:-Zz4O7J;m#-rB)2llQ*xTHjtblwm&kruUVa_v(&W')
	
	# Organization hash, sign, and verify

	rv = root_entry.generate_hash('BLAKE2B-256')
	assert not rv.error(), 'entry failed to hash'

	rv = root_entry.sign(initial_oskey, 'Organization')
	assert not rv.error(), 'Unexpected RetVal error %s' % rv.error()
	assert root_entry.signatures['Organization'], 'entry failed to org sign'

	rv = root_entry.verify_signature(initial_ovkey, 'Organization')
	assert not rv.error(), 'org entry failed to verify'

	status = root_entry.is_compliant()
	assert not status.error(), f"OrgEntry wasn't compliant: {str(status)}"

	card.entries.append(root_entry)
	cur.execute("INSERT INTO keycards(owner,creationtime,index,entry,fingerprint) " \
		"VALUES('organization',%s,%s,%s,%s);",
		(root_entry.fields['Timestamp'],root_entry.fields['Index'],
			root_entry.make_bytestring(-1).decode(), root_entry.hash))

	cur.execute("INSERT INTO orgkeys(creationtime, pubkey, privkey, purpose, fingerprint) "
				"VALUES(%s,%s,%s,'encrypt',%s);",
				(root_entry.fields['Timestamp'], initial_epubkey.as_string(),
				initial_eprivkey.as_string(), initial_epubhash.as_string()))

	cur.execute("INSERT INTO orgkeys(creationtime, pubkey, privkey, purpose, fingerprint) "
				"VALUES(%s,%s,%s,'sign',%s);",
				(root_entry.fields['Timestamp'], initial_ovkey.as_string(),
				initial_oskey.as_string(), initial_ovhash.as_string()))

	cur.close()
	dbconn.commit()	
	cur = dbconn.cursor()

	# Chain a new entry to the root

	status = card.chain(initial_oskey, False)
	assert not status.error(), f'keycard chain failed: {status}'

	# Save the keys to a separate RetVal so we can keep using status for return codes
	keys = status
	
	new_entry = status['entry']
	new_entry.prev_hash = root_entry.hash
	new_entry.generate_hash('BLAKE2B-256')
	assert not status.error(), f'chained entry failed to hash: {status}'
	
	status = card.verify()
	assert not status.error(), f'keycard failed to verify: {status}'

	cur.execute("INSERT INTO keycards(owner,creationtime,index,entry,fingerprint) " \
		"VALUES('organization',%s,%s,%s,%s);",
		(new_entry.fields['Timestamp'],new_entry.fields['Index'],
			new_entry.make_bytestring(-1).decode(), new_entry.hash))

	cur.execute("INSERT INTO orgkeys(creationtime, pubkey, privkey, purpose, fingerprint) "
				"VALUES(%s,%s,%s,'sign',%s);",
				(new_entry.fields['Timestamp'], keys['sign.public'],
				keys['sign.private'], keys['sign.pubhash']))

	cur.execute("INSERT INTO orgkeys(creationtime, pubkey, privkey, purpose, fingerprint) "
				"VALUES(%s,%s,%s,'encrypt',%s);",
				(new_entry.fields['Timestamp'], keys['encrypt.public'],
				keys['encrypt.private'], keys['encrypt.pubhash']))
	
	if keys.has_value('altsign.public'):
		cur.execute("INSERT INTO orgkeys(creationtime, pubkey, privkey, purpose, fingerprint) "
					"VALUES(%s,%s,%s,'altsign',%s);",
					(new_entry.fields['Timestamp'], keys['altsign.public'],
					keys['altsign.private'], keys['altsign.pubhash']))


	# Prereg the admin account
	admin_wid = utils.UUID('ae406c5e-2673-4d3e-af20-91325d9623ca')
	regcode = 'Undamaged Shining Amaretto Improve Scuttle Uptake'
	cur.execute(f"INSERT INTO prereg(wid, uid, domain, regcode) VALUES('{admin_wid}', 'admin', "
		f"'example.com', '{regcode}');")
	
	# Set up abuse/support forwarding to admin
	abuse_wid = 'f8cfdbdf-62fe-4275-b490-736f5fdc82e3'
	cur.execute("INSERT INTO workspaces(wid, uid, domain, password, status, wtype) "
		f"VALUES('{abuse_wid}', 'abuse', 'example.com', '-', 'active', 'alias');")
	cur.execute(f"INSERT INTO aliases(wid, alias) VALUES('{abuse_wid}', "
		f"'{'/'.join([admin_wid.as_string(), 'example.com'])}');")

	support_wid = 'f0309ef1-a155-4655-836f-55173cc1bc3b'
	cur.execute(f"INSERT INTO workspaces(wid, uid, domain, password, status, wtype) "
		f"VALUES('{support_wid}', 'support', 'example.com', '-', 'active', 'alias');")
	cur.execute(f"INSERT INTO aliases(wid, alias) VALUES('{support_wid}', "
		f"'{'/'.join([admin_wid.as_string(), 'example.com'])}');")
	
	cur.close()
	dbconn.commit()	

	admin_profile_data['wid'] = utils.UUID(admin_wid)
	admin_profile_data['domain'] = utils.Domain('example.com')
	admin_profile_data['address'] = utils.MAddress('admin/example.com')
	admin_profile_data['waddress'] = utils.WAddress(admin_wid.as_string() + 'example.com')

	return {
		'configfile' : load_server_config(),
		'ovkey' : keys['sign.public'],
		'oskey' : keys['sign.private'],
		'oekey' : keys['encrypt.public'],
		'odkey' : keys['encrypt.private'],
		'admin_wid' : utils.UUID(admin_wid),
		'admin_regcode' : regcode,
		'root_org_entry' : root_entry,
		'second_org_entry' : new_entry,
		'support_wid' : utils.UUID(support_wid),
		'abuse_wid' : utils.UUID(abuse_wid),
	}
Adds basic data to the database as if setupconfig had been run. It also rotates the org 
	keycard so that there are two entries. Returns data needed for tests, such as the keys
Adds basic data to the database as if setupconfig had been run. It also rotates the org
keycard so that there are two entries. Returns data needed for tests, such as the keys
Adds basic data to the database as if setupconfig had been run . It also rotates the org keycard so that there are two entries . Returns data needed for tests such as the keys
def init_server(dbconn) -> dict:
	cur = dbconn.cursor()
	card = keycard.Keycard('Organization')
	root_entry = keycard.OrgEntry()
	root_entry.set_fields({
		'Name':'Example, Inc.',
		'Contact-Admin':'c590b44c-798d-4055-8d72-725a7942f3f6/acme.com',
		'Language':'en',
		'Domain':'example.com',
		'Primary-Verification-Key':'ED25519:r#r*RiXIN-0n)BzP3bv`LA&t4LFEQNF0Q@$N~RF*',
		'Encryption-Key':'CURVE25519:SNhj2K`hgBd8>G>lW$!pXiM7S-B!Fbd9jT2&{{Az'
	})
	initial_ovkey = CryptoString(r'ED25519:r#r*RiXIN-0n)BzP3bv`LA&t4LFEQNF0Q@$N~RF*')
	initial_oskey = CryptoString(r'ED25519:{UNQmjYhz<(-ikOBYoEQpXPt<irxUF*nq25PoW=_')
	initial_ovhash = CryptoString(r'BLAKE2B-256:ag29av@TUvh-V5KaB2l}H=m?|w`}dvkS1S1&{cMo')
	initial_epubkey = CryptoString(r'CURVE25519:SNhj2K`hgBd8>G>lW$!pXiM7S-B!Fbd9jT2&{{Az')
	initial_eprivkey = CryptoString(r'CURVE25519:WSHgOhi+bg=<bO^4UoJGF-z9`+TBN{ds?7RZ;w3o')
	initial_epubhash = CryptoString(r'BLAKE2B-256:-Zz4O7J;m#-rB)2llQ*xTHjtblwm&kruUVa_v(&W')
	rv = root_entry.generate_hash('BLAKE2B-256')
	assert not rv.error(), 'entry failed to hash'
	rv = root_entry.sign(initial_oskey, 'Organization')
	assert not rv.error(), 'Unexpected RetVal error %s' % rv.error()
	assert root_entry.signatures['Organization'], 'entry failed to org sign'
	rv = root_entry.verify_signature(initial_ovkey, 'Organization')
	assert not rv.error(), 'org entry failed to verify'
	status = root_entry.is_compliant()
	assert not status.error(), f"OrgEntry wasn't compliant: {str(status)}"
	card.entries.append(root_entry)
	cur.execute("INSERT INTO keycards(owner,creationtime,index,entry,fingerprint) " \
		"VALUES('organization',%s,%s,%s,%s);",
		(root_entry.fields['Timestamp'],root_entry.fields['Index'],
			root_entry.make_bytestring(-1).decode(), root_entry.hash))
	cur.execute("INSERT INTO orgkeys(creationtime, pubkey, privkey, purpose, fingerprint) "
				"VALUES(%s,%s,%s,'encrypt',%s);",
				(root_entry.fields['Timestamp'], initial_epubkey.as_string(),
				initial_eprivkey.as_string(), initial_epubhash.as_string()))
	cur.execute("INSERT INTO orgkeys(creationtime, pubkey, privkey, purpose, fingerprint) "
				"VALUES(%s,%s,%s,'sign',%s);",
				(root_entry.fields['Timestamp'], initial_ovkey.as_string(),
				initial_oskey.as_string(), initial_ovhash.as_string()))
	cur.close()
	dbconn.commit()	
	cur = dbconn.cursor()
	status = card.chain(initial_oskey, False)
	assert not status.error(), f'keycard chain failed: {status}'
	keys = status
	new_entry = status['entry']
	new_entry.prev_hash = root_entry.hash
	new_entry.generate_hash('BLAKE2B-256')
	assert not status.error(), f'chained entry failed to hash: {status}'
	status = card.verify()
	assert not status.error(), f'keycard failed to verify: {status}'
	cur.execute("INSERT INTO keycards(owner,creationtime,index,entry,fingerprint) " \
		"VALUES('organization',%s,%s,%s,%s);",
		(new_entry.fields['Timestamp'],new_entry.fields['Index'],
			new_entry.make_bytestring(-1).decode(), new_entry.hash))
	cur.execute("INSERT INTO orgkeys(creationtime, pubkey, privkey, purpose, fingerprint) "
				"VALUES(%s,%s,%s,'sign',%s);",
				(new_entry.fields['Timestamp'], keys['sign.public'],
				keys['sign.private'], keys['sign.pubhash']))
	cur.execute("INSERT INTO orgkeys(creationtime, pubkey, privkey, purpose, fingerprint) "
				"VALUES(%s,%s,%s,'encrypt',%s);",
				(new_entry.fields['Timestamp'], keys['encrypt.public'],
				keys['encrypt.private'], keys['encrypt.pubhash']))
	if keys.has_value('altsign.public'):
		cur.execute("INSERT INTO orgkeys(creationtime, pubkey, privkey, purpose, fingerprint) "
					"VALUES(%s,%s,%s,'altsign',%s);",
					(new_entry.fields['Timestamp'], keys['altsign.public'],
					keys['altsign.private'], keys['altsign.pubhash']))
	admin_wid = utils.UUID('ae406c5e-2673-4d3e-af20-91325d9623ca')
	regcode = 'Undamaged Shining Amaretto Improve Scuttle Uptake'
	cur.execute(f"INSERT INTO prereg(wid, uid, domain, regcode) VALUES('{admin_wid}', 'admin', "
		f"'example.com', '{regcode}');")
	abuse_wid = 'f8cfdbdf-62fe-4275-b490-736f5fdc82e3'
	cur.execute("INSERT INTO workspaces(wid, uid, domain, password, status, wtype) "
		f"VALUES('{abuse_wid}', 'abuse', 'example.com', '-', 'active', 'alias');")
	cur.execute(f"INSERT INTO aliases(wid, alias) VALUES('{abuse_wid}', "
		f"'{'/'.join([admin_wid.as_string(), 'example.com'])}');")
	support_wid = 'f0309ef1-a155-4655-836f-55173cc1bc3b'
	cur.execute(f"INSERT INTO workspaces(wid, uid, domain, password, status, wtype) "
		f"VALUES('{support_wid}', 'support', 'example.com', '-', 'active', 'alias');")
	cur.execute(f"INSERT INTO aliases(wid, alias) VALUES('{support_wid}', "
		f"'{'/'.join([admin_wid.as_string(), 'example.com'])}');")
	cur.close()
	dbconn.commit()	
	admin_profile_data['wid'] = utils.UUID(admin_wid)
	admin_profile_data['domain'] = utils.Domain('example.com')
	admin_profile_data['address'] = utils.MAddress('admin/example.com')
	admin_profile_data['waddress'] = utils.WAddress(admin_wid.as_string() + 'example.com')
	return {
		'configfile' : load_server_config(),
		'ovkey' : keys['sign.public'],
		'oskey' : keys['sign.private'],
		'oekey' : keys['encrypt.public'],
		'odkey' : keys['encrypt.private'],
		'admin_wid' : utils.UUID(admin_wid),
		'admin_regcode' : regcode,
		'root_org_entry' : root_entry,
		'second_org_entry' : new_entry,
		'support_wid' : utils.UUID(support_wid),
		'abuse_wid' : utils.UUID(abuse_wid),
	}
def init_server ( dbconn ) -> dict : cur = dbconn . cursor ( ) card = keycard . Keycard ( 'Organization' ) root_entry = keycard . OrgEntry ( ) root_entry . set_fields ( { 'Name' : 'Example, Inc.' , 'Contact-Admin' : 'c590b44c-798d-4055-8d72-725a7942f3f6/acme.com' , 'Language' : 'en' , 'Domain' : 'example.com' , 'Primary-Verification-Key' : 'ED25519:r#r*RiXIN-0n)BzP3bv`LA&t4LFEQNF0Q@$N~RF*' , 'Encryption-Key' : 'CURVE25519:SNhj2K`hgBd8>G>lW$!pXiM7S-B!Fbd9jT2&{{Az' } ) initial_ovkey = CryptoString ( r'ED25519:r#r*RiXIN-0n)BzP3bv`LA&t4LFEQNF0Q@$N~RF*' ) initial_oskey = CryptoString ( r'ED25519:{UNQmjYhz<(-ikOBYoEQpXPt<irxUF*nq25PoW=_' ) initial_ovhash = CryptoString ( r'BLAKE2B-256:ag29av@TUvh-V5KaB2l}H=m?|w`}dvkS1S1&{cMo' ) initial_epubkey = CryptoString ( r'CURVE25519:SNhj2K`hgBd8>G>lW$!pXiM7S-B!Fbd9jT2&{{Az' ) initial_eprivkey = CryptoString ( r'CURVE25519:WSHgOhi+bg=<bO^4UoJGF-z9`+TBN{ds?7RZ;w3o' ) initial_epubhash = CryptoString ( r'BLAKE2B-256:-Zz4O7J;m#-rB)2llQ*xTHjtblwm&kruUVa_v(&W' ) rv = root_entry . generate_hash ( 'BLAKE2B-256' ) assert not rv . error ( ) , 'entry failed to hash' rv = root_entry . sign ( initial_oskey , 'Organization' ) assert not rv . error ( ) , 'Unexpected RetVal error %s' % rv . error ( ) assert root_entry . signatures [ 'Organization' ] , 'entry failed to org sign' rv = root_entry . verify_signature ( initial_ovkey , 'Organization' ) assert not rv . error ( ) , 'org entry failed to verify' status = root_entry . is_compliant ( ) assert not status . error ( ) , f"OrgEntry wasn't compliant: {str(status)}" card . entries . append ( root_entry ) cur . execute ( "INSERT INTO keycards(owner,creationtime,index,entry,fingerprint) " "VALUES('organization',%s,%s,%s,%s);" , ( root_entry . fields [ 'Timestamp' ] , root_entry . fields [ 'Index' ] , root_entry . make_bytestring ( - 1 ) . decode ( ) , root_entry . hash ) ) cur . execute ( "INSERT INTO orgkeys(creationtime, pubkey, privkey, purpose, fingerprint) " "VALUES(%s,%s,%s,'encrypt',%s);" , ( root_entry . fields [ 'Timestamp' ] , initial_epubkey . as_string ( ) , initial_eprivkey . as_string ( ) , initial_epubhash . as_string ( ) ) ) cur . execute ( "INSERT INTO orgkeys(creationtime, pubkey, privkey, purpose, fingerprint) " "VALUES(%s,%s,%s,'sign',%s);" , ( root_entry . fields [ 'Timestamp' ] , initial_ovkey . as_string ( ) , initial_oskey . as_string ( ) , initial_ovhash . as_string ( ) ) ) cur . close ( ) dbconn . commit ( ) cur = dbconn . cursor ( ) status = card . chain ( initial_oskey , False ) assert not status . error ( ) , f'keycard chain failed: {status}' keys = status new_entry = status [ 'entry' ] new_entry . prev_hash = root_entry . hash new_entry . generate_hash ( 'BLAKE2B-256' ) assert not status . error ( ) , f'chained entry failed to hash: {status}' status = card . verify ( ) assert not status . error ( ) , f'keycard failed to verify: {status}' cur . execute ( "INSERT INTO keycards(owner,creationtime,index,entry,fingerprint) " "VALUES('organization',%s,%s,%s,%s);" , ( new_entry . fields [ 'Timestamp' ] , new_entry . fields [ 'Index' ] , new_entry . make_bytestring ( - 1 ) . decode ( ) , new_entry . hash ) ) cur . execute ( "INSERT INTO orgkeys(creationtime, pubkey, privkey, purpose, fingerprint) " "VALUES(%s,%s,%s,'sign',%s);" , ( new_entry . fields [ 'Timestamp' ] , keys [ 'sign.public' ] , keys [ 'sign.private' ] , keys [ 'sign.pubhash' ] ) ) cur . execute ( "INSERT INTO orgkeys(creationtime, pubkey, privkey, purpose, fingerprint) " "VALUES(%s,%s,%s,'encrypt',%s);" , ( new_entry . fields [ 'Timestamp' ] , keys [ 'encrypt.public' ] , keys [ 'encrypt.private' ] , keys [ 'encrypt.pubhash' ] ) ) if keys . has_value ( 'altsign.public' ) : cur . execute ( "INSERT INTO orgkeys(creationtime, pubkey, privkey, purpose, fingerprint) " "VALUES(%s,%s,%s,'altsign',%s);" , ( new_entry . fields [ 'Timestamp' ] , keys [ 'altsign.public' ] , keys [ 'altsign.private' ] , keys [ 'altsign.pubhash' ] ) ) admin_wid = utils . UUID ( 'ae406c5e-2673-4d3e-af20-91325d9623ca' ) regcode = 'Undamaged Shining Amaretto Improve Scuttle Uptake' cur . execute ( f"INSERT INTO prereg(wid, uid, domain, regcode) VALUES('{admin_wid}', 'admin', " f"'example.com', '{regcode}');" ) abuse_wid = 'f8cfdbdf-62fe-4275-b490-736f5fdc82e3' cur . execute ( "INSERT INTO workspaces(wid, uid, domain, password, status, wtype) " f"VALUES('{abuse_wid}', 'abuse', 'example.com', '-', 'active', 'alias');" ) cur . execute ( f"INSERT INTO aliases(wid, alias) VALUES('{abuse_wid}', " f"'{'/'.join([admin_wid.as_string(), 'example.com'])}');" ) support_wid = 'f0309ef1-a155-4655-836f-55173cc1bc3b' cur . execute ( f"INSERT INTO workspaces(wid, uid, domain, password, status, wtype) " f"VALUES('{support_wid}', 'support', 'example.com', '-', 'active', 'alias');" ) cur . execute ( f"INSERT INTO aliases(wid, alias) VALUES('{support_wid}', " f"'{'/'.join([admin_wid.as_string(), 'example.com'])}');" ) cur . close ( ) dbconn . commit ( ) admin_profile_data [ 'wid' ] = utils . UUID ( admin_wid ) admin_profile_data [ 'domain' ] = utils . Domain ( 'example.com' ) admin_profile_data [ 'address' ] = utils . MAddress ( 'admin/example.com' ) admin_profile_data [ 'waddress' ] = utils . WAddress ( admin_wid . as_string ( ) + 'example.com' ) return { 'configfile' : load_server_config ( ) , 'ovkey' : keys [ 'sign.public' ] , 'oskey' : keys [ 'sign.private' ] , 'oekey' : keys [ 'encrypt.public' ] , 'odkey' : keys [ 'encrypt.private' ] , 'admin_wid' : utils . UUID ( admin_wid ) , 'admin_regcode' : regcode , 'root_org_entry' : root_entry , 'second_org_entry' : new_entry , 'support_wid' : utils . UUID ( support_wid ) , 'abuse_wid' : utils . UUID ( abuse_wid ) , }
Adds basic data to the database as if setupconfig had been run.
Adds basic data to the database as if setupconfig had been run .
'''Adds basic data to the database as if setupconfig had been run. It also rotates the org 
	keycard so that there are two entries. Returns data needed for tests, such as the keys''' # Start off by generating the org's root keycard entry and add to the database # Organization hash, sign, and verify # Chain a new entry to the root # Save the keys to a separate RetVal so we can keep using status for return codes # Prereg the admin account # Set up abuse/support forwarding to admin
dbconn