-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CSRF protection to cell, history, column and expr commands
- Loading branch information
Showing
43 changed files
with
618 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
main/tests/server/src/com/google/refine/commands/CommandTestBase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.google.refine.commands; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.io.IOException; | ||
import java.io.PrintWriter; | ||
import java.io.StringWriter; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
import org.testng.annotations.BeforeMethod; | ||
|
||
import com.google.refine.util.TestUtils; | ||
|
||
public class CommandTestBase { | ||
protected HttpServletRequest request = null; | ||
protected HttpServletResponse response = null; | ||
protected Command command = null; | ||
protected StringWriter writer = null; | ||
|
||
@BeforeMethod | ||
public void setUpRequestResponse() { | ||
request = mock(HttpServletRequest.class); | ||
response = mock(HttpServletResponse.class); | ||
writer = new StringWriter(); | ||
try { | ||
when(response.getWriter()).thenReturn(new PrintWriter(writer)); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
/** | ||
* Convenience method to check that CSRF protection was triggered | ||
*/ | ||
protected void assertCSRFCheckFailed() { | ||
TestUtils.assertEqualAsJson("{\"code\":\"error\",\"message\":\"Missing or invalid csrf_token parameter\"}", writer.toString()); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
main/tests/server/src/com/google/refine/commands/EngineDependentCommandTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.google.refine.commands; | ||
|
||
import java.io.IOException; | ||
|
||
import javax.servlet.ServletException; | ||
import javax.servlet.http.HttpServletRequest; | ||
|
||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.Test; | ||
|
||
import com.google.refine.browsing.EngineConfig; | ||
import com.google.refine.model.AbstractOperation; | ||
import com.google.refine.model.Project; | ||
|
||
public class EngineDependentCommandTests extends CommandTestBase { | ||
|
||
private static class EngineDependentCommandStub extends EngineDependentCommand { | ||
|
||
@Override | ||
protected AbstractOperation createOperation(Project project, HttpServletRequest request, | ||
EngineConfig engineConfig) throws Exception { | ||
return null; | ||
} | ||
|
||
} | ||
|
||
@BeforeMethod | ||
public void setUpCommand() { | ||
command = new EngineDependentCommandStub(); | ||
} | ||
|
||
@Test | ||
public void testCSRFProtection() throws ServletException, IOException { | ||
command.doPost(request, response); | ||
assertCSRFCheckFailed(); | ||
} | ||
} | ||
|
25 changes: 25 additions & 0 deletions
25
main/tests/server/src/com/google/refine/commands/cell/JoinMultiValueCellsCommandTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.google.refine.commands.cell; | ||
|
||
import java.io.IOException; | ||
|
||
import javax.servlet.ServletException; | ||
|
||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.Test; | ||
|
||
import com.google.refine.commands.CommandTestBase; | ||
import com.google.refine.commands.cell.JoinMultiValueCellsCommand; | ||
|
||
public class JoinMultiValueCellsCommandTests extends CommandTestBase { | ||
|
||
@BeforeMethod | ||
public void setUpCommand() { | ||
command = new JoinMultiValueCellsCommand(); | ||
} | ||
|
||
@Test | ||
public void testCSRFProtection() throws ServletException, IOException { | ||
command.doPost(request, response); | ||
assertCSRFCheckFailed(); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
main/tests/server/src/com/google/refine/commands/cell/KeyValueColumnizeCommandTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.google.refine.commands.cell; | ||
|
||
import java.io.IOException; | ||
|
||
import javax.servlet.ServletException; | ||
|
||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.Test; | ||
|
||
import com.google.refine.commands.CommandTestBase; | ||
|
||
public class KeyValueColumnizeCommandTests extends CommandTestBase { | ||
|
||
@BeforeMethod | ||
public void setUpCommand() { | ||
command = new KeyValueColumnizeCommand(); | ||
} | ||
|
||
@Test | ||
public void testCSRFProtection() throws ServletException, IOException { | ||
command.doPost(request, response); | ||
assertCSRFCheckFailed(); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
main/tests/server/src/com/google/refine/commands/cell/SplitMultiValueCellsCommandTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.google.refine.commands.cell; | ||
|
||
import java.io.IOException; | ||
|
||
import javax.servlet.ServletException; | ||
|
||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.Test; | ||
|
||
import com.google.refine.commands.CommandTestBase; | ||
|
||
public class SplitMultiValueCellsCommandTests extends CommandTestBase { | ||
@BeforeMethod | ||
public void setUpCommand() { | ||
command = new SplitMultiValueCellsCommand(); | ||
} | ||
|
||
@Test | ||
public void testCSRFProtection() throws ServletException, IOException { | ||
command.doPost(request, response); | ||
assertCSRFCheckFailed(); | ||
} | ||
} |
Oops, something went wrong.