Skip to content
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
178 changes: 178 additions & 0 deletions CapMonsterCloud.Client.IntegrationTests/IntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@
}

[Test]
public async Task RecaptchaV2_IncorrectProxyPort_ShouldThrowArgumentException()

Check warning on line 827 in CapMonsterCloud.Client.IntegrationTests/IntegrationTests.cs

View workflow job for this annotation

GitHub Actions / build

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 827 in CapMonsterCloud.Client.IntegrationTests/IntegrationTests.cs

View workflow job for this annotation

GitHub Actions / build

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
Action actual = () => ObjectGen.RecaptchaV2.CreateTask(
proxyPort: Gen.RandomInt(65535));
Expand Down Expand Up @@ -1071,5 +1071,183 @@
sut.GetActualRequests().Should().BeEquivalentTo(expectedRequests);
actual.Should().BeEquivalentTo(expectedResult);
}

[Test]
public async Task Temu_ShouldSolve()
{
var clientKey = Gen.RandomString();
var taskId = Gen.RandomInt();

var captchaRequest = ObjectGen.TemuTask.CreateTask();
var expectedResult = ObjectGen.TemuTask.CreateSolution();

var expectedRequests = new List<(RequestType Type, string ExpectedRequest)>
{
(
Type: RequestType.CreateTask,
ExpectedRequest: JsonConvert.SerializeObject(new
{ clientKey = clientKey, task = captchaRequest, softId = 53 })
),
(
Type: RequestType.GetTaskResult,
ExpectedRequest: JsonConvert.SerializeObject(new { clientKey = clientKey, taskId = taskId })
),
};

var captchaResults = new List<object>
{
new { taskId = taskId, errorId = 0, errorCode = (string)null! },
new
{
status = "ready",
solution = new
{
domains = expectedResult.Solution.Domains
},
errorId = 0,
errorCode = (string)null!
}
};

var sut = new Sut(clientKey);
sut.SetupHttpServer(captchaResults);

var actual = await sut.SolveAsync(captchaRequest);

sut.GetActualRequests().Should().BeEquivalentTo(expectedRequests);
actual.Should().BeEquivalentTo(expectedResult);
}

[Test]
public async Task MTCaptcha_ShouldSolve()
{
var clientKey = Gen.RandomString();
var taskId = Gen.RandomInt();

var captchaRequest = ObjectGen.MTCaptchaTask.CreateTask();
var expectedResult = ObjectGen.MTCaptchaTask.CreateSolution();

var expectedRequests = new List<(RequestType Type, string ExpectedRequest)>
{
(
Type: RequestType.CreateTask,
ExpectedRequest: JsonConvert.SerializeObject(new
{ clientKey = clientKey, task = captchaRequest, softId = 53 })
),
(
Type: RequestType.GetTaskResult,
ExpectedRequest: JsonConvert.SerializeObject(new { clientKey = clientKey, taskId = taskId })
),
};

var captchaResults = new List<object>
{
new { taskId = taskId, errorId = 0, errorCode = (string)null! },
new
{
status = "ready",
solution = new { token = expectedResult.Solution.Value },
errorId = 0,
errorCode = (string)null!
}
};

var sut = new Sut(clientKey);
sut.SetupHttpServer(captchaResults);

var actual = await sut.SolveAsync(captchaRequest);

sut.GetActualRequests().Should().BeEquivalentTo(expectedRequests);
actual.Should().BeEquivalentTo(expectedResult);
}

[Test]
public async Task Yidun_ShouldSolve()
{
var clientKey = Gen.RandomString();
var taskId = Gen.RandomInt();

var captchaRequest = ObjectGen.YidunTask.CreateTask();
var expectedResult = ObjectGen.YidunTask.CreateSolution();

var expectedRequests = new List<(RequestType Type, string ExpectedRequest)>
{
(
Type: RequestType.CreateTask,
ExpectedRequest: JsonConvert.SerializeObject(new
{ clientKey = clientKey, task = captchaRequest, softId = 53 })
),
(
Type: RequestType.GetTaskResult,
ExpectedRequest: JsonConvert.SerializeObject(new { clientKey = clientKey, taskId = taskId })
),
};

var captchaResults = new List<object>
{
new { taskId = taskId, errorId = 0, errorCode = (string)null! },
new
{
status = "ready",
solution = new { token = expectedResult.Solution.Value },
errorId = 0,
errorCode = (string)null!
}
};

var sut = new Sut(clientKey);
sut.SetupHttpServer(captchaResults);

var actual = await sut.SolveAsync(captchaRequest);

sut.GetActualRequests().Should().BeEquivalentTo(expectedRequests);
actual.Should().BeEquivalentTo(expectedResult);
}

[Test]
public async Task Prosopo_ShouldSolve()
{
var clientKey = Gen.RandomString();
var taskId = Gen.RandomInt();

var captchaRequest = ObjectGen.ProsopoTask.CreateTask();
var expectedResult = ObjectGen.ProsopoTask.CreateSolution();

var expectedRequests = new List<(RequestType Type, string ExpectedRequest)>
{
(
Type: RequestType.CreateTask,
ExpectedRequest: JsonConvert.SerializeObject(new
{ clientKey = clientKey, task = captchaRequest, softId = 53 })
),
(
Type: RequestType.GetTaskResult,
ExpectedRequest: JsonConvert.SerializeObject(new { clientKey = clientKey, taskId = taskId })
),
};

var captchaResults = new List<object>
{
new { taskId = taskId, errorId = 0, errorCode = (string)null! },
new
{
status = "ready",
solution = new
{
token = expectedResult.Solution.Value
},
errorId = 0,
errorCode = (string)null!
}
};

var sut = new Sut(clientKey);
sut.SetupHttpServer(captchaResults);

var actual = await sut.SolveAsync(captchaRequest);

sut.GetActualRequests().Should().BeEquivalentTo(expectedRequests);
actual.Should().BeEquivalentTo(expectedResult);
}
}
}
127 changes: 127 additions & 0 deletions CapMonsterCloud.Client.IntegrationTests/ObjectGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -546,5 +546,132 @@ public static CaptchaResult<BinanceTaskResponse> CreateSolution()
};
}
}

public static class TemuTask
{
public static TemuCustomTaskRequest CreateTask()
{
return new TemuCustomTaskRequest(Gen.RandomString())
{
WebsiteUrl = Gen.RandomUri().ToString(),
UserAgent = Gen.UserAgent(),
Proxy = new ProxyContainer(Gen.RandomString(), Gen.RandomInt(0, 65535), Gen.RandomEnum<ProxyType>(), Gen.RandomString(), Gen.RandomString())
};
}

public static CaptchaResult<CustomTaskResponse> CreateSolution()
{
return new CaptchaResult<CustomTaskResponse>
{
Error = null,
Solution = new CustomTaskResponse
{
Domains = new Dictionary<string, CustomTaskResponse.DomainInfo>
{
{
"www.temu.com",
new CustomTaskResponse.DomainInfo
{
Cookies = new Dictionary<string, string>
{
{ "verifyAuthToken", Gen.RandomString() },
{ "api_uid", Gen.RandomString() }
}
}
}
}
}
};
}
}

public static class MTCaptchaTask
{
public static MTCaptchaTaskRequest CreateTask()
{
return new MTCaptchaTaskRequest
{
WebsiteUrl = Gen.RandomUri().ToString(),
WebsiteKey = Gen.RandomString(),
Invisible = Gen.RandomBool(),
PageAction = Gen.RandomString(),
UserAgent = Gen.UserAgent(),
Proxy = new ProxyContainer(
Gen.RandomString(), Gen.RandomInt(0, 65535),
Gen.RandomEnum<ProxyType>(), Gen.RandomString(), Gen.RandomString())
};
}

public static CaptchaResult<MTCaptchaTaskResponse> CreateSolution()
{
return new CaptchaResult<MTCaptchaTaskResponse>
{
Error = null,
Solution = new MTCaptchaTaskResponse
{
Value = Gen.RandomString()
}
};
}
}

public static class YidunTask
{
public static YidunTaskRequest CreateTask()
{
return new YidunTaskRequest
{
WebsiteUrl = Gen.RandomUri().ToString(),
WebsiteKey = Gen.RandomString(),
UserAgent = Gen.UserAgent(),
// Enterprise ïîëÿ ïî æåëàíèþ:
YidunGetLib = Gen.RandomUri().ToString(),
YidunApiServerSubdomain = Gen.RandomString(),
Challenge = Gen.RandomString(),
Hcg = Gen.RandomString(),
Hct = Gen.RandomLong(1, long.MaxValue),
Proxy = new ProxyContainer(
Gen.RandomString(), Gen.RandomInt(0, 65535),
Gen.RandomEnum<ProxyType>(), Gen.RandomString(), Gen.RandomString())
};
}

public static CaptchaResult<YidunTaskResponse> CreateSolution()
{
return new CaptchaResult<YidunTaskResponse>
{
Error = null,
Solution = new YidunTaskResponse
{
Value = Gen.RandomString(),
}
};
}
}

public static class ProsopoTask
{
public static ProsopoTaskRequest CreateTask()
{
return new ProsopoTaskRequest
{
WebsiteUrl = Gen.RandomUri().ToString(),
WebsiteKey = Gen.RandomString(),
Proxy = new ProxyContainer(Gen.RandomString(), Gen.RandomInt(0, 65535), Gen.RandomEnum<ProxyType>(), Gen.RandomString(), Gen.RandomString())
};
}

public static CaptchaResult<ProsopoTaskResponse> CreateSolution()
{
return new CaptchaResult<ProsopoTaskResponse>
{
Error = null,
Solution = new ProsopoTaskResponse
{
Value = Gen.RandomString(),
}
};
}
}
}
}
12 changes: 12 additions & 0 deletions CapMonsterCloud.Client.IntegrationTests/Sut.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,18 @@ public async Task<CaptchaResult<CustomTaskResponse>> SolveAsync(

public async Task<CaptchaResult<DynamicComplexImageTaskResponse>> SolveAsync(
RecognitionComplexImageTaskRequest request) => await _cloudClient.SolveAsync(request);

public async Task<CaptchaResult<ProsopoTaskResponse>> SolveAsync(
ProsopoTaskRequest request) => await _cloudClient.SolveAsync<ProsopoTaskResponse>(request);

public async Task<CaptchaResult<CustomTaskResponse>> SolveAsync(
TemuCustomTaskRequest request) => await _cloudClient.SolveAsync<CustomTaskResponse>(request);

public async Task<CaptchaResult<MTCaptchaTaskResponse>> SolveAsync(
MTCaptchaTaskRequest request) => await _cloudClient.SolveAsync<MTCaptchaTaskResponse>(request);

public async Task<CaptchaResult<YidunTaskResponse>> SolveAsync(
YidunTaskRequest request) => await _cloudClient.SolveAsync<YidunTaskResponse>(request);

public async Task<decimal> GetBalanceAsync()
{
Expand Down
4 changes: 2 additions & 2 deletions CapMonsterCloud.Client/CapMonsterCloud.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageIcon>logo.png</PackageIcon>
<RepositoryUrl>https://github.com/ZennoLab/capmonstercloud-client-dotnet</RepositoryUrl>
<Version>3.0.1</Version>
<PackageReleaseNotes>Fixed DataDome request parameters</PackageReleaseNotes>
<Version>3.1.0</Version>
<PackageReleaseNotes>Add Yidun, Temu, Prosopo, MTCaptcha solving support</PackageReleaseNotes>
</PropertyGroup>

<ItemGroup>
Expand Down
39 changes: 39 additions & 0 deletions CapMonsterCloud.Client/CapMonsterCloudClient_GetResultTimeouts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,45 @@ private static GetResultTimeouts GetTimeouts(Type type)
Timeout = TimeSpan.FromSeconds(15)
}
},
{
typeof(TemuCustomTaskRequest),
new GetResultTimeouts
{
FirstRequestDelay = TimeSpan.FromSeconds(1),
RequestsInterval = TimeSpan.FromSeconds(3),
Timeout = TimeSpan.FromSeconds(180)
}
},
{
typeof(MTCaptchaTaskRequest),
new GetResultTimeouts
{
FirstRequestDelay = TimeSpan.FromSeconds(1),
FirstRequestNoCacheDelay = TimeSpan.FromSeconds(10),
RequestsInterval = TimeSpan.FromSeconds(3),
Timeout = TimeSpan.FromSeconds(180)
}
},
{
typeof(YidunTaskRequest),
new GetResultTimeouts
{
FirstRequestDelay = TimeSpan.FromSeconds(1),
FirstRequestNoCacheDelay = TimeSpan.FromSeconds(10),
RequestsInterval = TimeSpan.FromSeconds(3),
Timeout = TimeSpan.FromSeconds(180)
}
},
{
typeof(ProsopoTaskRequest),
new GetResultTimeouts
{
FirstRequestDelay = TimeSpan.FromSeconds(1),
FirstRequestNoCacheDelay = TimeSpan.FromSeconds(10),
RequestsInterval = TimeSpan.FromSeconds(3),
Timeout = TimeSpan.FromSeconds(180)
}
},
};
}
}
Loading
Loading