Skip to content

Commit

Permalink
[Misc] Remove deprecated calls (raised by SonarQube)
Browse files Browse the repository at this point in the history
* Always use secure() (thanks to Thomas)
  • Loading branch information
vmassol committed Sep 13, 2024
1 parent 51bb122 commit cc7fd41
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import org.xwiki.test.ui.TestUtils;
import org.xwiki.test.ui.po.LiveTableElement;

import static org.apache.commons.lang3.RandomStringUtils.insecure;
import static org.apache.commons.lang3.RandomStringUtils.secure;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
Expand Down Expand Up @@ -77,7 +77,7 @@ void entryNameWithURLSpecialCharacters(TestReference testReference, TestUtils te

// Test
EntryNamePane entryNamePane = homePage.clickAddNewEntry();
String entryName = "A?b=c&d#" + insecure().nextAlphanumeric(3);
String entryName = "A?b=c&d#" + secure().nextAlphanumeric(3);
entryNamePane.setName(entryName);
EntryEditPage entryEditPage = entryNamePane.clickAdd();
entryEditPage.setValue("description", "This is a test panel.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public static String saveRequest(HttpServletRequest request)
// Generate a random key to identify this request
String key;
do {
key = RandomStringUtils.randomAlphanumeric(8);
key = RandomStringUtils.secure().randomAlphanumeric(8);
} while (savedRequests.containsKey(key));
// Store the saved request
savedRequests.put(key, savedRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import javax.mail.internet.MimeMessage;

import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.RandomStringUtils;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -46,7 +45,7 @@
import com.icegreen.greenmail.util.GreenMail;
import com.icegreen.greenmail.util.ServerSetupTest;

import static org.apache.commons.lang3.RandomStringUtils.insecure;
import static org.apache.commons.lang3.RandomStringUtils.secure;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand Down Expand Up @@ -102,7 +101,7 @@ public void resetForgottenPassword(TestUtils setup) throws Exception
{
setup.forceGuestUser();

String userName = "testUser" + insecure().nextAlphanumeric(6);
String userName = "testUser" + secure().nextAlphanumeric(6);
String password = "password";
String newPassword = "newPasswörd";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private DocumentModelBridge mockDocument(DocumentReference documentReference) th
{
StringBuilder id = new StringBuilder(documentReference.getLastSpaceReference().getName());
// Allow different instances of the same document to exist.
id.append('.').append(documentReference.getName()).append(RandomStringUtils.insecure().nextAlphanumeric(3));
id.append('.').append(documentReference.getName()).append(RandomStringUtils.secure().nextAlphanumeric(3));
DocumentModelBridge document = mock(DocumentModelBridge.class, id.toString());

when(document.getDocumentReference()).thenReturn(documentReference);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import org.xwiki.test.docker.junit5.UITest;
import org.xwiki.test.ui.TestUtils;

import static org.apache.commons.lang3.RandomStringUtils.insecure;
import static org.apache.commons.lang3.RandomStringUtils.secure;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

Expand Down Expand Up @@ -62,7 +62,7 @@ void setUp(TestUtils setup)
void addRemoveTag(TestUtils setup, TestReference testReference)
{
TaggablePage taggablePage = resetTaggablePage(setup, testReference);
String tag = insecure().nextAlphanumeric(4);
String tag = secure().nextAlphanumeric(4);
assertFalse(taggablePage.hasTag(tag));
AddTagsPane addTagsPane = taggablePage.addTags();
addTagsPane.setTags(tag);
Expand All @@ -80,13 +80,13 @@ void addRemoveTag(TestUtils setup, TestReference testReference)
void cancelAddTag(TestUtils setup, TestReference testReference)
{
TaggablePage taggablePage = resetTaggablePage(setup, testReference);
String firstTag = insecure().nextAlphanumeric(4);
String firstTag = secure().nextAlphanumeric(4);
assertFalse(taggablePage.hasTag(firstTag));
AddTagsPane addTagsPane = taggablePage.addTags();
addTagsPane.setTags(firstTag);
addTagsPane.cancel();

String secondTag = insecure().nextAlphanumeric(4);
String secondTag = secure().nextAlphanumeric(4);
assertFalse(taggablePage.hasTag(secondTag));
addTagsPane = taggablePage.addTags();
addTagsPane.setTags(secondTag);
Expand All @@ -103,9 +103,9 @@ void cancelAddTag(TestUtils setup, TestReference testReference)
void addManyRemoveOneTag(TestUtils setup, TestReference testReference)
{
TaggablePage taggablePage = resetTaggablePage(setup, testReference);
String firstTag = insecure().nextAlphanumeric(4);
String firstTag = secure().nextAlphanumeric(4);
assertFalse(taggablePage.hasTag(firstTag));
String secondTag = insecure().nextAlphanumeric(4);
String secondTag = secure().nextAlphanumeric(4);
assertFalse(taggablePage.hasTag(secondTag));

AddTagsPane addTagsPane = taggablePage.addTags();
Expand All @@ -126,7 +126,7 @@ void addManyRemoveOneTag(TestUtils setup, TestReference testReference)
void addExistingTag(TestUtils setup, TestReference testReference)
{
TaggablePage taggablePage = resetTaggablePage(setup, testReference);
String tag = insecure().nextAlphanumeric(4);
String tag = secure().nextAlphanumeric(4);
assertFalse(taggablePage.hasTag(tag));
AddTagsPane addTagsPane = taggablePage.addTags();
addTagsPane.setTags(tag);
Expand All @@ -147,7 +147,7 @@ void addExistingTag(TestUtils setup, TestReference testReference)
void testAddTagContainingPipe(TestUtils setup, TestReference testReference)
{
TaggablePage taggablePage = resetTaggablePage(setup, testReference);
String tag = insecure().nextAlphanumeric(3) + "|" + insecure().nextAlphanumeric(3);
String tag = secure().nextAlphanumeric(3) + "|" + secure().nextAlphanumeric(3);
assertFalse(taggablePage.hasTag(tag));
AddTagsPane addTagsPane = taggablePage.addTags();
addTagsPane.setTags(tag);
Expand All @@ -169,9 +169,9 @@ void testAddTagContainingPipe(TestUtils setup, TestReference testReference)
void stripLeadingAndTrailingSpacesFromTags(TestUtils setup, TestReference testReference)
{
TaggablePage taggablePage = resetTaggablePage(setup, testReference);
String firstTag = insecure().nextAlphanumeric(4);
String firstTag = secure().nextAlphanumeric(4);
assertFalse(taggablePage.hasTag(firstTag));
String secondTag = insecure().nextAlphanumeric(4);
String secondTag = secure().nextAlphanumeric(4);
assertFalse(taggablePage.hasTag(secondTag));

AddTagsPane addTagsPane = taggablePage.addTags();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ private void handleConversionErrors(RequestParameterConversionResult conversionR
private String save(RequestParameterConversionResult conversionResult)
{
// Generate a random key to identify the request.
String key = RandomStringUtils.randomAlphanumeric(4);
String key = RandomStringUtils.secure().nextAlphanumeric(4);
MutableServletRequest request = conversionResult.getRequest();

// Save the output on the session.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void testRollback() throws Exception
@Test
public void testSaveOfThreeHundredKilobyteDocument() throws Exception
{
final String content = insecure().nextAlphanumeric(300000);
final String content = secure().nextAlphanumeric(300000);
final HttpMethod ret =
this.doPostAsAdmin(this.spaceName, this.pageName, null, "save", null,
new HashMap<String, String>() {{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void testEditButtonTriggersInlineEditing()
@Test
public void testInlineEditCanChangeTitle()
{
String title = insecure().nextAlphanumeric(4);
String title = secure().nextAlphanumeric(4);
getUtil().gotoPage(getTestClassName(), getTestMethodName(), "edit", "editor=inline&title=" + title);
InlinePage inlinePage = new InlinePage();
// Check if the title specified on the request is properly displayed.
Expand Down Expand Up @@ -88,7 +88,7 @@ public void testInlineEditCanChangeParent()
@IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See https://jira.xwiki.org/browse/XE-1177")
public void testInlineEditPreservesTitle()
{
String title = insecure().nextAlphanumeric(4);
String title = secure().nextAlphanumeric(4);
getUtil().gotoPage(getTestClassName(), getTestMethodName(), "save", "title=" + title);
ViewPage vp = new ViewPage();
Assert.assertEquals(title, vp.getDocumentTitle());
Expand Down Expand Up @@ -134,8 +134,8 @@ public void testInlineEditPreservesParent()
@IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See https://jira.xwiki.org/browse/XE-1177")
public void testInlineEditPreservesTags()
{
String tag1 = insecure().nextAlphanumeric(4);
String tag2 = insecure().nextAlphanumeric(4);
String tag1 = secure().nextAlphanumeric(4);
String tag2 = secure().nextAlphanumeric(4);
getUtil().gotoPage(getTestClassName(), getTestMethodName(), "save", "tags=" + tag1 + "%7C" + tag2);
TaggablePage taggablePage = new TaggablePage();
Assert.assertTrue(taggablePage.hasTag(tag1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void testSwitchToWysiwygWithAdvancedContent()
@IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See https://jira.xwiki.org/browse/XE-1146")
public void testPreviewDisplaysPageTitle()
{
String title = insecure().nextAlphanumeric(3);
String title = secure().nextAlphanumeric(3);
this.editPage.setTitle(title);
this.editPage.clickPreview();
// The preview page has the action buttons but otherwise it is similar to a view page.
Expand Down

0 comments on commit cc7fd41

Please sign in to comment.