2
0

mpw-tests was not checking mpw_tests.xml's keyID.

This commit is contained in:
Maarten Billemont 2017-09-22 18:23:08 -04:00
parent 34540f0844
commit dc7089c38c

View File

@ -57,6 +57,7 @@ int main(int argc, char *const argv[]) {
MPKeyPurpose keyPurpose = mpw_purposeWithName( (char *)keyPurposeString );
// Run the test case.
do {
fprintf( stdout, "test case %s... ", id );
if (!xmlStrlen( result )) {
fprintf( stdout, "abstract.\n" );
@ -68,29 +69,39 @@ int main(int argc, char *const argv[]) {
(char *)fullName, (char *)masterPassword, algorithm );
if (!masterKey) {
ftl( "Couldn't derive master key.\n" );
abort();
}
// Check the master key.
MPKeyID testKeyID = mpw_id_buf( masterKey, MPMasterKeySize );
if (xmlStrcmp( keyID, BAD_CAST testKeyID ) != 0) {
++failedTests;
fprintf( stdout, "FAILED! (keyID: got %s != expected %s)\n", testKeyID, keyID );
continue;
}
// 2. calculate the site password.
const char *sitePassword = mpw_siteResult(
const char *testResult = mpw_siteResult(
masterKey, (char *)siteName, siteCounter, keyPurpose, (char *)keyContext, resultType, NULL, algorithm );
mpw_free( &masterKey, MPMasterKeySize );
if (!sitePassword) {
if (!testResult) {
ftl( "Couldn't derive site password.\n" );
continue;
}
// Check the result.
if (xmlStrcmp( result, BAD_CAST sitePassword ) == 0)
fprintf( stdout, "pass.\n" );
else {
// Check the site result.
if (xmlStrcmp( result, BAD_CAST testResult ) != 0) {
++failedTests;
fprintf( stdout, "FAILED! (got %s != expected %s)\n", sitePassword, result );
fprintf( stdout, "FAILED! (result: got %s != expected %s)\n", testResult, result );
mpw_free_string( &testResult );
continue;
}
mpw_free_string( &testResult );
fprintf( stdout, "pass.\n" );
} while(false);
// Free test case.
mpw_free_string( &sitePassword );
xmlFree( id );
xmlFree( fullName );
xmlFree( masterPassword );