Skip to content

Commit

Permalink
[test] Prevent hard-coded path
Browse files Browse the repository at this point in the history
The hardcoded path used in this test conflicts with a pre-existing path by another user/process. This commit adds an existence check and a bit of randomness in the directory name.

Fixes SMACK-955
  • Loading branch information
guusdk committed Nov 4, 2024
1 parent 7ca5fb1 commit d5fe94f
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.Collections;

import org.jivesoftware.smack.test.util.SmackTestSuite;
import org.jivesoftware.smack.util.StringUtils;

import org.jivesoftware.smackx.ox.crypto.PainlessOpenPgpProvider;
import org.jivesoftware.smackx.ox.element.SecretkeyElement;
Expand All @@ -51,7 +52,11 @@ public class SecretKeyBackupHelperTest extends SmackTestSuite {
private static final File basePath;

static {
basePath = new File(org.apache.commons.io.FileUtils.getTempDirectory(), "ox_secret_keys");
File path;
do {
path = new File(org.apache.commons.io.FileUtils.getTempDirectory(), "ox_secret_keys_" + StringUtils.randomString(3));
} while (path.exists());
basePath = path;
}

@Test
Expand Down

0 comments on commit d5fe94f

Please sign in to comment.