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

hide slim symbol values prefixed with SECRET_ on the slim runner side #1333

Merged
merged 5 commits into from
Oct 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
Test
---
!3 When a symbol is prefixed with SECRET, it's contents will not be shown upon accessing the symbol

!| script |
|given page|SecretSymbolTest|with content|!-!define TEST_SYSTEM {slim}

|import |
|fitnesse.slim.test|
|fitnesse.fixtures |

|script |echo fixture |
|$SECRET_symbol=|echo|this is secret info |
|set name |$SECRET_symbol |
|check |echo|$SECRET_symbol|this is secret info|
-! |
|check |request page |SecretSymbolTest?test |200 |
|ensure|content contains|!-$SECRET_symbol->[*****]-! |
|ensure|content contains|&lt;span class="pass">this is secret info</span>|
|show |content |

14 changes: 8 additions & 6 deletions src/fitnesse/testsystems/slim/SlimTestContextImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
// Released under the terms of the CPL Common Public License version 1.0.
package fitnesse.testsystems.slim;

import fitnesse.testsystems.ExecutionResult;
import fitnesse.testsystems.TestPage;
import fitnesse.testsystems.TestSummary;
import fitnesse.testsystems.slim.tables.ScenarioTable;
import fitnesse.testsystems.slim.tables.ScriptTable;
import fitnesse.util.TimeMeasurement;

import java.util.ArrayList;
Expand All @@ -12,12 +17,6 @@
import java.util.List;
import java.util.Map;

import fitnesse.testsystems.ExecutionResult;
import fitnesse.testsystems.TestPage;
import fitnesse.testsystems.TestSummary;
import fitnesse.testsystems.slim.tables.ScenarioTable;
import fitnesse.testsystems.slim.tables.ScriptTable;

public class SlimTestContextImpl implements SlimTestContext {
private final Map<String, String> symbols = new HashMap<>();
private final Map<String, ScenarioTable> scenarios = new HashMap<>(512);
Expand All @@ -36,6 +35,9 @@ public SlimTestContextImpl(TestPage pageToTest) {

@Override
public String getSymbol(String symbolName) {
if (symbolName.startsWith("SECRET_")) {
return "*****";
}
return symbols.get(symbolName);
}

Expand Down
14 changes: 14 additions & 0 deletions test/fitnesse/testsystems/slim/tables/SlimTableTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ public void replaceSymbolsShouldReplaceSimpleSymbol() throws Exception {
assertEquals("this is a", table.replaceSymbols("this is $x"));
}

@Test
public void replaceSymbolsShouldReplaceSecretSymbol() throws Exception {
SlimTable table = new MockTable();
table.setSymbol("SECRET_x", "a");
assertEquals("this is *****", table.replaceSymbols("this is $SECRET_x"));
}

@Test
public void replaceSymbolsShouldReplaceMoreThanOneSymbol() throws Exception {
SlimTable table = new MockTable();
Expand Down Expand Up @@ -87,6 +94,13 @@ public void replaceSymbolsFullExpansion_ShouldReplaceSimpleSymbol() throws Excep
assertEquals("this is $x->[a]", table.replaceSymbolsWithFullExpansion("this is $x"));
}

@Test
public void replaceSymbolsFullExpansion_ShouldReplaceSecretSymbol() throws Exception {
SlimTable table = new MockTable();
table.setSymbol("SECRET_x", "a");
assertEquals("this is $SECRET_x->[*****]", table.replaceSymbolsWithFullExpansion("this is $SECRET_x"));
}

@Test
public void replaceSymbolsFullExpansion_ShouldReplaceMoreThanOneSymbol() throws Exception {
SlimTable table = new MockTable();
Expand Down