<commit_before>#!/usr/bin/env bash
#
#TEST: Test to check to check that the enforcer automatically generates keys correctly
#TEST: This test does mulitple runs of the enforcer with zones
#TEST: on different policies and checks it generates the right number
#TEST: of the right kind of key. Tries to test algorithm and length mixtures
#TEST: shared keys and standby

#DISABLED: ON FREEBSD - due to pthread seg fault on freebsd64
#DISABLED: ON SOLARIS T2000- as key generation takes too long!

ENFORCER_WAIT=90	# Seconds we wait for enforcer to run

add_zones() {
	for (( ZONE_COUNT=$1; ZONE_COUNT<=$2; ZONE_COUNT++ ))
	do
		sed s/ods./ods_$ZONE_COUNT./g unsigned/ods > unsigned/ods_$ZONE_COUNT &&
		log_this ods-zone-add_$3 ods-ksmutil zone add --zone ods_$ZONE_COUNT --policy Policy$3
	done 	
}

if [ -n "$HAVE_MYSQL" ]; then
        ods_setup_conf conf.xml conf-mysql.xml
fi &&

case "$DISTRIBUTION" in
	freebsd )
		return 0
		;;
esac

ods_reset_env &&

##################  Basic behaviour  ###########################
# Fail with no zones
export ENFORCER_TIMESHIFT='01-01-2010 12:00' &&
log_this_timeout ods-control-enforcer-start $ENFORCER_WAIT ods-enforcerd -1 &&
syslog_waitfor $ENFORCER_WAIT 'ods-enforcerd: .*all done' &&

syslog_waitfor $ENFORCER_WAIT 'ods-enforcerd: .*No zones on policy Policy1, skipping...' &&

# Generate keys with algorithm 7, length 2048
add_zones 1 1 1 && 
log_this_timeout ods-control-enforcer-start $ENFORCER_WAIT ods-enforcerd -1 &&
syslog_waitfor $ENFORCER_WAIT 'ods-enforcerd: .*all done' 

syslog_grep_count 1  "ods-enforcerd: .*1 zone(s) found on policy \"Policy1\""  &&
syslog_grep_count 1  'ods-enforcerd: .*1 new KSK(s) (2048 bits) need to be created.'  &&
syslog_grep_count 1  'ods-enforcerd: .*5 new ZSK(s) (2048 bits) need to be created.' &&
log_this enforcer-keylist   ods-hsmutil list &&
log_grep enforcer-keylist   stdout "6 keys found." && 

##################  1. Keys not shared, same alg & length ###########################<commit_msg>TEST: Turn off another test on T2000 as too slow....<commit_after>#!/usr/bin/env bash
#
#TEST: Test to check to check that the enforcer automatically generates keys correctly
#TEST: This test does mulitple runs of the enforcer with zones
#TEST: on different policies and checks it generates the right number
#TEST: of the right kind of key. Tries to test algorithm and length mixtures
#TEST: shared keys and standby

#DISABLED: ON FREEBSD - due to pthread seg fault on freebsd64
#DISABLED: ON SOLARIS T2000- as key generation takes too long!

ENFORCER_WAIT=90	# Seconds we wait for enforcer to run

add_zones() {
	for (( ZONE_COUNT=$1; ZONE_COUNT<=$2; ZONE_COUNT++ ))
	do
		sed s/ods./ods_$ZONE_COUNT./g unsigned/ods > unsigned/ods_$ZONE_COUNT &&
		log_this ods-zone-add_$3 ods-ksmutil zone add --zone ods_$ZONE_COUNT --policy Policy$3
	done 	
}

if [ -n "$HAVE_MYSQL" ]; then
        ods_setup_conf conf.xml conf-mysql.xml
fi &&

case "$DISTRIBUTION" in
	sunos )	
		if uname -m 2>/dev/null | $GREP -q -i sun4v 2>/dev/null; then
			return 0	
		fi
		;;			
	freebsd )	
		return 0
		;;
esac

ods_reset_env &&

##################  Basic behaviour  ###########################
# Fail with no zones
export ENFORCER_TIMESHIFT='01-01-2010 12:00' &&
log_this_timeout ods-control-enforcer-start $ENFORCER_WAIT ods-enforcerd -1 &&
syslog_waitfor $ENFORCER_WAIT 'ods-enforcerd: .*all done' &&

syslog_waitfor $ENFORCER_WAIT 'ods-enforcerd: .*No zones on policy Policy1, skipping...' &&

# Generate keys with algorithm 7, length 2048
add_zones 1 1 1 && 
log_this_timeout ods-control-enforcer-start $ENFORCER_WAIT ods-enforcerd -1 &&
syslog_waitfor $ENFORCER_WAIT 'ods-enforcerd: .*all done' 

syslog_grep_count 1  "ods-enforcerd: .*1 zone(s) found on policy \"Policy1\""  &&
syslog_grep_count 1  'ods-enforcerd: .*1 new KSK(s) (2048 bits) need to be created.'  &&
syslog_grep_count 1  'ods-enforcerd: .*5 new ZSK(s) (2048 bits) need to be created.' &&
log_this enforcer-keylist   ods-hsmutil list &&
log_grep enforcer-keylist   stdout "6 keys found." && 

##################  1. Keys not shared, same alg & length ###########################
{'fraction_non_alphanumeric': 0.14528668610301262, 'fraction_numerical': 0.027696793002915453, 'mean_word_length': 4.332901554404145, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '3869148', 'n_tokens_mistral': 1616, 'n_tokens_neox': 1505, 'n_words': 461}