-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
completely disable networking stack inside containers and restrict pe…
…rmissions inside the execution container
- Loading branch information
1 parent
3922d2d
commit e271bbf
Showing
16 changed files
with
265 additions
and
18 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
79 changes: 79 additions & 0 deletions
79
src/test/java/com/cp/compiler/security/CSecurityTests.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,79 @@ | ||
package com.cp.compiler.security; | ||
|
||
import com.cp.compiler.contract.Language; | ||
import com.cp.compiler.contract.RemoteCodeCompilerResponse; | ||
import com.cp.compiler.contract.testcases.TestCaseResult; | ||
import com.cp.compiler.controllers.CompilerController; | ||
import com.cp.compiler.models.Verdict; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.mock.web.MockMultipartFile; | ||
import org.springframework.test.annotation.DirtiesContext; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
|
||
@Slf4j | ||
@DirtiesContext | ||
@SpringBootTest | ||
class CSecurityTests { | ||
|
||
@Autowired | ||
private CompilerController compilerController; | ||
|
||
/** | ||
* Running a system level command should return runtime error statusResponse. | ||
* | ||
* @throws Exception the exception | ||
*/ | ||
@DisplayName("C Security Command Line execution Should Return Runtime Error") | ||
@Test | ||
void RunningASystemCommandShouldReturnRuntimeErrorVerdict() throws Exception { | ||
// Given | ||
File sourceCodeFile = new File("src/test/resources/sources/security/c/CommandLine.c"); | ||
MultipartFile sourceCode = new MockMultipartFile( | ||
"Test1.c", | ||
"Test1.c", | ||
null, | ||
new FileInputStream(sourceCodeFile)); | ||
|
||
// Dummy expected output | ||
File expectedOutputFile = new File("src/test/resources/outputs/Test1.txt"); | ||
MultipartFile expectedOutput = new MockMultipartFile( | ||
"Test1.txt", | ||
"Test1.txt", | ||
null, | ||
new FileInputStream(expectedOutputFile)); | ||
|
||
// When | ||
ResponseEntity<RemoteCodeCompilerResponse> responseEntity = compilerController.compile( | ||
Language.C, | ||
sourceCode, | ||
null, | ||
expectedOutput, | ||
10, | ||
500, | ||
null, | ||
null, | ||
""); | ||
|
||
for (TestCaseResult testCaseResult: responseEntity.getBody().getExecution().getTestCasesResult().values()) { | ||
log.info("Container std output = {}", testCaseResult.getOutput()); | ||
log.info("Container stderr output = {}", testCaseResult.getError()); | ||
} | ||
|
||
// Then | ||
Assertions.assertFalse( | ||
responseEntity | ||
.getBody() | ||
.getExecution() | ||
.getError() | ||
.isEmpty()); | ||
} | ||
} |
Oops, something went wrong.