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

replace test hashes #420

Merged
merged 2 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
29 changes: 29 additions & 0 deletions dotnet/Vaas/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/dotnet
{
"name": "C# (.NET)",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/dotnet:1-8.0-bookworm",
"customizations": {
"vscode": {
"extensions": [
"ms-dotnettools.csdevkit"
]
}
}
// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [5000, 5001],
// "portsAttributes": {
// "5001": {
// "protocol": "https"
// }
// }
// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "dotnet restore",
// Configure tool-specific properties.
// "customizations": {},
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
12 changes: 12 additions & 0 deletions dotnet/Vaas/.github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for more information:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
# https://containers.dev/guide/dependabot

version: 2
updates:
- package-ecosystem: "devcontainers"
directory: "/"
schedule:
interval: weekly
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<values>
<value name="VS.TelemetryApi.ChannelsDisposeLatency" type="int">1</value>
<value name="VS.TelemetryApi.DroppedEventsDuringDisposing" type="int">0</value>
<value name="VS.TelemetryApi.TotalDisposeLatency" type="int">4</value>
</values>
48 changes: 24 additions & 24 deletions dotnet/Vaas/test/Vaas.Test/IntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,21 @@ public async void FromSha256SingleMaliciousHash()
{
var vaas = await AuthenticateWithCredentials();
var verdict = await vaas.ForSha256Async(
new ChecksumSha256("000005c43196142f01d615a67b7da8a53cb0172f8e9317a2ec9a0a39a1da6fe8"),
new ChecksumSha256("ab5788279033b0a96f2d342e5f35159f103f69e0191dd391e036a1cd711791a2"),
CancellationToken.None);
Assert.Equal(Verdict.Malicious, verdict.Verdict);
Assert.Equal("000005c43196142f01d615a67b7da8a53cb0172f8e9317a2ec9a0a39a1da6fe8", verdict.Sha256);
Assert.Equal("ab5788279033b0a96f2d342e5f35159f103f69e0191dd391e036a1cd711791a2", verdict.Sha256);
}

[Fact]
public async void FromSha256SingleCleanHash()
{
var vaas = await AuthenticateWithCredentials();
var verdict = await vaas.ForSha256Async(
new ChecksumSha256("3A78F382E8E2968EC201B33178102E06DB72E4F2D1505E058A4613C1E977825C"),
new ChecksumSha256("cd617c5c1b1ff1c94a52ab8cf07192654f271a3f8bad49490288131ccb9efc1e"),
CancellationToken.None);
Assert.Equal(Verdict.Clean, verdict.Verdict);
Assert.Equal("3A78F382E8E2968EC201B33178102E06DB72E4F2D1505E058A4613C1E977825C", verdict.Sha256, true);
Assert.Equal("cd617c5c1b1ff1c94a52ab8cf07192654f271a3f8bad49490288131ccb9efc1e", verdict.Sha256, true);
}

[Fact(Skip = "Remove Skip to test keepalive")]
Expand Down Expand Up @@ -105,11 +105,11 @@ public async void From256ListMultipleHashes()
var vaas = await AuthenticateWithCredentials();
var verdictList = await vaas.ForSha256ListAsync(myList, CancellationToken.None);
Assert.Equal(Verdict.Malicious, verdictList[0].Verdict);
Assert.Equal("000005c43196142f01d615a67b7da8a53cb0172f8e9317a2ec9a0a39a1da6fe8", verdictList[0].Sha256, true);
Assert.Equal("ab5788279033b0a96f2d342e5f35159f103f69e0191dd391e036a1cd711791a2", verdictList[0].Sha256, true);
Assert.Equal(Verdict.Clean, verdictList[1].Verdict);
Assert.Equal("3A78F382E8E2968EC201B33178102E06DB72E4F2D1505E058A4613C1E977825C", verdictList[1].Sha256, true);
Assert.Equal("cd617c5c1b1ff1c94a52ab8cf07192654f271a3f8bad49490288131ccb9efc1e", verdictList[1].Sha256, true);
Assert.Equal(Verdict.Unknown, verdictList[2].Verdict);
Assert.Equal("110005c43196142f01d615a67b7da8a53cb0172f8e9317a2ec9a0a39a1da6fe9", verdictList[2].Sha256, true);
Assert.Equal("1f72c1111111111111f912e40b7323a0192a300b376186c10f6803dc5efe28df", verdictList[2].Sha256, true);
}


Expand Down Expand Up @@ -180,7 +180,7 @@ public async Task ForUrl_WithUrlWithStatusCode4xx_ThrowsVaasClientException()
"Call failed with status code 404 (Not Found): GET https://upload.production.vaas.gdatasecurity.de/nocontenthere",
e.Message);
}

[Fact]
public async Task ForStream_WithEicarString_ReturnsMalicious()
{
Expand All @@ -190,14 +190,14 @@ public async Task ForStream_WithEicarString_ReturnsMalicious()
var eicarBytes = System.Text.Encoding.UTF8.GetBytes("X5O!P%@AP[4\\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*");
targetStream.Write(eicarBytes, 0, eicarBytes.Length);
targetStream.Position = 0;

// Act
var verdict = await vaas.ForStreamAsync(targetStream, CancellationToken.None);

// Assert
Assert.Equal(Verdict.Malicious, verdict.Verdict);
}

[Fact]
public async Task ForStream_WithCleanString_ReturnsClean()
{
Expand All @@ -207,10 +207,10 @@ public async Task ForStream_WithCleanString_ReturnsClean()
var cleanBytes = System.Text.Encoding.UTF8.GetBytes("This is a clean file");
targetStream.Write(cleanBytes, 0, cleanBytes.Length);
targetStream.Position = 0;

// Act
var verdict = await vaas.ForStreamAsync(targetStream, CancellationToken.None);

// Assert
Assert.Equal(Verdict.Clean, verdict.Verdict);
}
Expand All @@ -223,14 +223,14 @@ public async Task ForStream_WithCleanUrl_ReturnsClean()
var url = new Uri("https://raw.githubusercontent.com/GDATASoftwareAG/vaas/main/Readme.md");
var response = await _httpClient.SendAsync(new HttpRequestMessage(HttpMethod.Get, url), CancellationToken.None);
var targetStream = await response.Content.ReadAsStreamAsync();

// Act
var verdict = await vaas.ForStreamAsync(targetStream, CancellationToken.None);

// Assert
Assert.Equal(Verdict.Clean, verdict.Verdict);
}

[Fact]
public async Task ForStream_WithEicarUrl_ReturnsEicar()
{
Expand All @@ -239,10 +239,10 @@ public async Task ForStream_WithEicarUrl_ReturnsEicar()
var url = new Uri("https://secure.eicar.org/eicar.com.txt");
var response = await _httpClient.SendAsync(new HttpRequestMessage(HttpMethod.Get, url), CancellationToken.None);
var targetStream = await response.Content.ReadAsStreamAsync();

// Act
var verdict = await vaas.ForStreamAsync(targetStream, CancellationToken.None);

// Assert
Assert.Equal(Verdict.Malicious, verdict.Verdict);
}
Expand Down Expand Up @@ -305,32 +305,32 @@ public async Task Connect_WithResourceOwnerPasswordGrantAuthenticator()
var vaas = provider.GetRequiredService<IVaas>();
await vaas.Connect(CancellationToken.None);
}

[Fact]
public async Task ForStream_WithEicarUrl_ReturnsMaliciousWithDetectionsAndMimeType()
{
var vaas = await AuthenticateWithCredentials();
var url = new Uri("https://secure.eicar.org/eicar.com.txt");
var response = await _httpClient.SendAsync(new HttpRequestMessage(HttpMethod.Get, url), CancellationToken.None);
var targetStream = await response.Content.ReadAsStreamAsync();

var verdict = await vaas.ForStreamAsync(targetStream, CancellationToken.None);

Assert.Equal(Verdict.Malicious, verdict.Verdict);
Assert.NotNull(verdict.LibMagic);
Assert.NotNull(verdict.Detections);
Assert.Equal("text/plain", verdict.LibMagic.MimeType);
Assert.Contains(verdict.Detections, detection => detection.Virus == "EICAR_TEST_FILE");
}

[Fact]
public async Task ForUrl_WithEicarUrl_ReturnsMaliciousWithDetectionAndMimeType()
{
var vaas = await AuthenticateWithCredentials();
var uri = new Uri("https://secure.eicar.org/eicar.com");

var verdict = await vaas.ForUrlAsync(uri, CancellationToken.None);

Assert.Equal(Verdict.Malicious, verdict.Verdict);
Assert.NotNull(verdict.LibMagic);
Assert.NotNull(verdict.Detections);
Expand Down
12 changes: 6 additions & 6 deletions golang/vaas/pkg/vaas/vaas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ func (tf *testFixture) tearDown(t *testing.T) {

func TestVaas_ForSha256(t *testing.T) {
const (
cleanSha256 string = "3A78F382E8E2968EC201B33178102E06DB72E4F2D1505E058A4613C1E977825C"
maliciousSha256 string = "00000b68934493af2f5954593fe8127b9dda6d4b520e78265aa5875623b58c9c"
unknownSha256 string = "110005c43196142f01d615a67b7da8a53cb0172f8e9317a2ec9a0a39a1da6fe9"
cleanSha256 string = "cd617c5c1b1ff1c94a52ab8cf07192654f271a3f8bad49490288131ccb9efc1e"
maliciousSha256 string = "ab5788279033b0a96f2d342e5f35159f103f69e0191dd391e036a1cd711791a2"
unknownSha256 string = "1f72c1111111111111f912e40b7323a0192a300b376186c10f6803dc5efe28df"
)
type fields struct {
testingOptions options.VaasOptions
Expand Down Expand Up @@ -443,9 +443,9 @@ func TestVaas_ForSha256List(t *testing.T) {
vaasClient := fixture.setUp(t)
defer fixture.tearDown(t)

maliciousSha256 := strings.ToLower("00000b68934493af2f5954593fe8127b9dda6d4b520e78265aa5875623b58c9c")
cleanSha256 := strings.ToLower("3A78F382E8E2968EC201B33178102E06DB72E4F2D1505E058A4613C1E977825C")
unknownSha256 := strings.ToLower("110005c43196142f01d615a67b7da8a53cb0172f8e9317a2ec9a0a39a1da6fe9")
maliciousSha256 := strings.ToLower("ab5788279033b0a96f2d342e5f35159f103f69e0191dd391e036a1cd711791a2")
cleanSha256 := strings.ToLower("cd617c5c1b1ff1c94a52ab8cf07192654f271a3f8bad49490288131ccb9efc1e")
unknownSha256 := strings.ToLower("1f72c1111111111111f912e40b7323a0192a300b376186c10f6803dc5efe28df")

verdicts, err := vaasClient.ForSha256List(context.Background(), []string{maliciousSha256, cleanSha256, unknownSha256})
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ public void resourceOwnerPasswordAuthenticatorGetToken() throws Exception {
@Test
public void forSha256SingleMaliciousHash() throws Exception {
var vaas = this.getVaasWithCredentials();
var sha256 = new Sha256("000005c43196142f01d615a67b7da8a53cb0172f8e9317a2ec9a0a39a1da6fe8");
var sha256 = new Sha256("ab5788279033b0a96f2d342e5f35159f103f69e0191dd391e036a1cd711791a2");

var verdict = vaas.forSha256(sha256);
vaas.disconnect();

assertEquals(Verdict.MALICIOUS, verdict.getVerdict());
assertTrue("000005c43196142f01d615a67b7da8a53cb0172f8e9317a2ec9a0a39a1da6fe8"
assertTrue("ab5788279033b0a96f2d342e5f35159f103f69e0191dd391e036a1cd711791a2"
.equalsIgnoreCase(verdict.getSha256()));
}

Expand Down Expand Up @@ -134,50 +134,26 @@ public String getToken() throws IOException, InterruptedException {
}

@Test
public void forSha256MultipleMaliciousHash() throws Exception {
public void forSha256MultipleHashes() throws Exception {
var vaas = this.getVaasWithCredentials();
var sha256_1 = new Sha256("000005c43196142f01d615a67b7da8a53cb0172f8e9317a2ec9a0a39a1da6fe8");
var sha256_2 = new Sha256("00000b68934493af2f5954593fe8127b9dda6d4b520e78265aa5875623b58c9c");
var sha256_3 = new Sha256("00000f83e3120f79a21b7b395dd3dd6a9c31ce00857f78d7cf487476ca75fd1a");
var sha256_1 = new Sha256("ab5788279033b0a96f2d342e5f35159f103f69e0191dd391e036a1cd711791a2");
var sha256_2 = new Sha256("cd617c5c1b1ff1c94a52ab8cf07192654f271a3f8bad49490288131ccb9efc1e");
var sha256_3 = new Sha256("1f72c1111111111111f912e40b7323a0192a300b376186c10f6803dc5efe28df");

var verdict_1 = vaas.forSha256(sha256_1);
var verdict_2 = vaas.forSha256(sha256_2);
var verdict_3 = vaas.forSha256(sha256_3);
vaas.disconnect();

assertEquals(Verdict.MALICIOUS, verdict_1.getVerdict());
assertEquals(Verdict.MALICIOUS, verdict_2.getVerdict());
assertEquals(Verdict.MALICIOUS, verdict_3.getVerdict());

assertTrue("000005c43196142f01d615a67b7da8a53cb0172f8e9317a2ec9a0a39a1da6fe8"
.equalsIgnoreCase(verdict_1.getSha256()));
assertTrue("00000b68934493af2f5954593fe8127b9dda6d4b520e78265aa5875623b58c9c"
.equalsIgnoreCase(verdict_2.getSha256()));
assertTrue("00000f83e3120f79a21b7b395dd3dd6a9c31ce00857f78d7cf487476ca75fd1a"
.equalsIgnoreCase(verdict_3.getSha256()));
}

@Test
public void forSha256MultipleCleanHash() throws Exception {
var vaas = this.getVaasWithCredentials();
var sha256_1 = new Sha256("3A78F382E8E2968EC201B33178102E06DB72E4F2D1505E058A4613C1E977825C");
var sha256_2 = new Sha256("1AFAFE9157FF5670BBEC8CE622F45D1CE51B3EE77B7348D3A237E232F06C5391");
var sha256_3 = new Sha256("4447FAACEFABA8F040822101E2A4103031660DE9139E70ECFF9AA3A89455A783");

var verdict_1 = vaas.forSha256(sha256_1);
var verdict_2 = vaas.forSha256(sha256_2);
var verdict_3 = vaas.forSha256(sha256_3);
vaas.disconnect();

assertEquals(Verdict.CLEAN, verdict_1.getVerdict());
assertEquals(Verdict.CLEAN, verdict_2.getVerdict());
assertEquals(Verdict.CLEAN, verdict_3.getVerdict());
assertEquals(Verdict.UNKNOWN, verdict_3.getVerdict());

assertTrue("3A78F382E8E2968EC201B33178102E06DB72E4F2D1505E058A4613C1E977825C"
assertTrue("ab5788279033b0a96f2d342e5f35159f103f69e0191dd391e036a1cd711791a2"
.equalsIgnoreCase(verdict_1.getSha256()));
assertTrue("1AFAFE9157FF5670BBEC8CE622F45D1CE51B3EE77B7348D3A237E232F06C5391"
assertTrue("cd617c5c1b1ff1c94a52ab8cf07192654f271a3f8bad49490288131ccb9efc1e"
.equalsIgnoreCase(verdict_2.getSha256()));
assertTrue("4447FAACEFABA8F040822101E2A4103031660DE9139E70ECFF9AA3A89455A783"
assertTrue("1f72c1111111111111f912e40b7323a0192a300b376186c10f6803dc5efe28df"
.equalsIgnoreCase(verdict_3.getSha256()));
}

Expand Down
45 changes: 8 additions & 37 deletions php/tests/vaas/VaasTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ final class VaasTest extends TestCase
{
use ProphecyTrait;

const MALICIOUS_HASH = "000005c43196142f01d615a67b7da8a53cb0172f8e9317a2ec9a0a39a1da6fe8";
const MALICIOUS_HASH = "ab5788279033b0a96f2d342e5f35159f103f69e0191dd391e036a1cd711791a2";
const MALICIOUS_URL = "https://secure.eicar.org/eicar.com.txt";

public function setUp(): void
Expand Down Expand Up @@ -162,39 +162,10 @@ public function testForSha256MaliciousSha256WithFlag_BothFlagsFalse_GetsMaliciou
$this->assertEqualsIgnoringCase(self::MALICIOUS_HASH, $verdict->Sha256);
}

public function testForMultipleMaliciousSha256_GetsMaliciousResponses(): void
{
$vaas = $this->_getVaas();
$vaas->Connect($this->getClientCredentialsGrantAuthenticator()->getToken());

$uuid1 = $this->getUuid();
$sha256_1 = "000005c43196142f01d615a67b7da8a53cb0172f8e9317a2ec9a0a39a1da6fe8";
$uuid2 = $this->getUuid();
$sha256_2 = "00000b68934493af2f5954593fe8127b9dda6d4b520e78265aa5875623b58c9c";
$uuid3 = $this->getUuid();
$sha256_3 = "00000f83e3120f79a21b7b395dd3dd6a9c31ce00857f78d7cf487476ca75fd1a";

$verdict1 = $vaas->ForSha256($sha256_1, $uuid1);
$verdict2 = $vaas->ForSha256($sha256_2, $uuid2);
$verdict3 = $vaas->ForSha256($sha256_3, $uuid3);

$this->assertEquals(Verdict::MALICIOUS, $verdict1->Verdict);
$this->assertEquals($uuid1, $verdict1->Guid);
$this->assertEqualsIgnoringCase($sha256_1, $verdict1->Sha256);

$this->assertEquals(Verdict::MALICIOUS, $verdict2->Verdict);
$this->assertEquals($uuid2, $verdict2->Guid);
$this->assertEqualsIgnoringCase($sha256_2, $verdict2->Sha256);

$this->assertEquals(Verdict::MALICIOUS, $verdict3->Verdict);
$this->assertEquals($uuid3, $verdict3->Guid);
$this->assertEqualsIgnoringCase($sha256_3, $verdict3->Sha256);
}

public function testForSha256CleanSha256_GetsCleanResponse(): void
{
$uuid = $this->getUuid();
$cleanSha256 = "3A78F382E8E2968EC201B33178102E06DB72E4F2D1505E058A4613C1E977825C";
$cleanSha256 = "cd617c5c1b1ff1c94a52ab8cf07192654f271a3f8bad49490288131ccb9efc1e";

$vaas = $this->_getVaas();
$vaas->Connect($this->getClientCredentialsGrantAuthenticator()->getToken());
Expand All @@ -219,14 +190,14 @@ public function testForSha256CleanSha256_GetsCleanResponse(): void
// $this->assertEqualsIgnoringCase($pupSha256, $verdict->Sha256);
// }

public function testForMultipleCleanFiles_GetsCleanResponses(): void
public function testForMultipleHashes_GetsResponse(): void
{
$uuid1 = $this->getUuid();
$uuid2 = $this->getUuid();
$uuid3 = $this->getUuid();
$cleanHash1 = "3A78F382E8E2968EC201B33178102E06DB72E4F2D1505E058A4613C1E977825C";
$cleanHash2 = "1AFAFE9157FF5670BBEC8CE622F45D1CE51B3EE77B7348D3A237E232F06C5391";
$cleanHash3 = "4447FAACEFABA8F040822101E2A4103031660DE9139E70ECFF9AA3A89455A783";
$cleanHash1 = "ab5788279033b0a96f2d342e5f35159f103f69e0191dd391e036a1cd711791a2";
$cleanHash2 = "cd617c5c1b1ff1c94a52ab8cf07192654f271a3f8bad49490288131ccb9efc1e";
$cleanHash3 = "1f72c1111111111111f912e40b7323a0192a300b376186c10f6803dc5efe28df";

$vaas = $this->_getVaas();
$vaas->Connect($this->getClientCredentialsGrantAuthenticator()->getToken());
Expand All @@ -235,13 +206,13 @@ public function testForMultipleCleanFiles_GetsCleanResponses(): void
$verdict2 = $vaas->ForSha256($cleanHash2, $uuid2);
$verdict3 = $vaas->ForSha256($cleanHash3, $uuid3);

$this->assertEquals(Verdict::CLEAN, $verdict1->Verdict);
$this->assertEquals(Verdict::MALICIOUS, $verdict1->Verdict);
$this->assertEquals($uuid1, $verdict1->Guid);
$this->assertEqualsIgnoringCase($cleanHash1, $verdict1->Sha256);
$this->assertEquals(Verdict::CLEAN, $verdict2->Verdict);
$this->assertEquals($uuid2, $verdict2->Guid);
$this->assertEqualsIgnoringCase($cleanHash2, $verdict2->Sha256);
$this->assertEquals(Verdict::CLEAN, $verdict3->Verdict);
$this->assertEquals(Verdict::UNKNOWN, $verdict3->Verdict);
$this->assertEquals($uuid3, $verdict3->Guid);
$this->assertEqualsIgnoringCase($cleanHash3, $verdict3->Sha256);
}
Expand Down
Loading
Loading