Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only immediate assertions work in usage pattern tests #310

Open
rakshitkr opened this issue Oct 24, 2020 · 1 comment
Open

Only immediate assertions work in usage pattern tests #310

rakshitkr opened this issue Oct 24, 2020 · 1 comment
Labels

Comments

@rakshitkr
Copy link
Contributor

rakshitkr commented Oct 24, 2020

For a generated predicate, its corresponding assertion in the usage pattern test is expected to be immediately after the statement (that has the object for which predicate is generated). Is it a correct behaviour? The predicate gets negated even though there are not statements explicitly negating it. An example of a negating statement would be clearPassword() from PBEKeySpec rule

In the sample test case below, the first hasEnsuredPredicate assertion on key passes, but fails for the second assertion of same type.

@Test
	public void keyStoreInvalidTest10() throws NoSuchAlgorithmException, UnrecoverableKeyException, IOException,
			KeyStoreException, CertificateException {

		char[] passwordKey = null;
		String alias = null;
		Entry entry = null;
		InputStream fileinput = null;
		String keyStoreAlgorithm = null;
		String aliasSet = null;
		ProtectionParameter protParamSet = null;
		char[] passwordIn = null;
		LoadStoreParameter paramStore = null;

		KeyStore keyStore0 = KeyStore.getInstance(keyStoreAlgorithm);
		keyStore0.load(fileinput, passwordIn);
		Key key = keyStore0.getKey(alias, passwordKey);
		Assertions.hasEnsuredPredicate(key); // PASSES
		keyStore0.setEntry(aliasSet, entry, protParamSet);
		keyStore0.store(paramStore);
		Assertions.hasEnsuredPredicate(key); // FAILS
		Assertions.mustBeInAcceptingState(keyStore0);
	}
@rakshitkr rakshitkr added bug and removed question labels Dec 12, 2020
@rakshitkr rakshitkr changed the title Assertions for optional predicates Only immediate assertions work in usage pattern tests Dec 12, 2020
@rakshitkr
Copy link
Contributor Author

rakshitkr commented Dec 13, 2020

For a conditional predicate, its corresponding assertion in the usage pattern test is expected to be immediately after the statement (that has the object for which predicate is generated).

@Test
	public void secureRandomValidTest11() throws NoSuchAlgorithmException {

		long lSeed = 0;

		SecureRandom secureRandom0 = SecureRandom.getInstance("SHA1PRNG");
                Assertions.hasEnsuredPredicate(secureRandom0); // PASSES
		secureRandom0.setSeed(lSeed);
		Assertions.hasEnsuredPredicate(secureRandom0); // FAILS
		Assertions.mustBeInAcceptingState(secureRandom0);

	}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant