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
46 changes: 46 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 @@ -1203,5 +1203,51 @@
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);
}
}
}
27 changes: 26 additions & 1 deletion CapMonsterCloud.Client.IntegrationTests/ObjectGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ public static YidunTaskRequest CreateTask()
WebsiteUrl = Gen.RandomUri().ToString(),
WebsiteKey = Gen.RandomString(),
UserAgent = Gen.UserAgent(),
// Enterprise поля по желанию:
// Enterprise ïîëÿ ïî æåëàíèþ:
YidunGetLib = Gen.RandomUri().ToString(),
YidunApiServerSubdomain = Gen.RandomString(),
Challenge = Gen.RandomString(),
Expand All @@ -648,5 +648,30 @@ public static CaptchaResult<YidunTaskResponse> CreateSolution()
};
}
}

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(),
}
};
}
}
}
}
3 changes: 3 additions & 0 deletions CapMonsterCloud.Client.IntegrationTests/Sut.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ 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);
Expand Down
10 changes: 10 additions & 0 deletions CapMonsterCloud.Client/CapMonsterCloudClient_GetResultTimeouts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,16 @@ private static GetResultTimeouts GetTimeouts(Type type)
Timeout = TimeSpan.FromSeconds(180)
}
},
{
typeof(ProsopoTaskRequest),
new GetResultTimeouts
{
FirstRequestDelay = TimeSpan.FromSeconds(1),
FirstRequestNoCacheDelay = TimeSpan.FromSeconds(10),
RequestsInterval = TimeSpan.FromSeconds(3),
Timeout = TimeSpan.FromSeconds(180)
}
},
};
}
}
38 changes: 38 additions & 0 deletions CapMonsterCloud.Client/Requests/ProsopoTaskRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Newtonsoft.Json;
using System.ComponentModel.DataAnnotations;
using Zennolab.CapMonsterCloud.Responses;

namespace Zennolab.CapMonsterCloud.Requests
{
/// <summary>
/// Prosopo Procaptcha recognition request.
/// </summary>
/// <example>
/// https://docs.capmonster.cloud/docs/captchas/prosopo-task
/// </example>
public sealed class ProsopoTaskRequest : CaptchaRequestBaseWithProxy<ProsopoTaskResponse>
{
/// <summary>
/// Recognition task type
/// </summary>
public const string TaskType = "ProsopoTask";

/// <inheritdoc/>
[JsonProperty("type", Required = Required.Always)]
public sealed override string Type => TaskType;

/// <summary>
/// The full URL of the CAPTCHA page.
/// </summary>
[JsonProperty("websiteURL", Required = Required.Always)]
[Url]
public string WebsiteUrl { get; set; }

/// <summary>
/// The value of the "siteKey" parameter found on the page.
/// </summary>
[JsonProperty("websiteKey", Required = Required.Always)]
[StringLength(int.MaxValue, MinimumLength = 1)]
public string WebsiteKey { get; set; }
}
}
19 changes: 19 additions & 0 deletions CapMonsterCloud.Client/Responses/ProsopoTaskResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Newtonsoft.Json;

namespace Zennolab.CapMonsterCloud.Responses
{
/// <summary>
/// Prosopo Procaptcha recognition response
/// </summary>
public sealed class ProsopoTaskResponse : CaptchaResponseBase
{
/// <summary>
/// Prosopo token
/// </summary>
/// <example>
/// 0x00016c68747470733a2f2f70726f6e6f6465332e70726f736f706f2e696f...
/// </example>
[JsonProperty("token")]
public string Value { get; set; }
}
}
Loading