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
43 changes: 43 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 @@ -1160,5 +1160,48 @@
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);
}
}
}
34 changes: 34 additions & 0 deletions CapMonsterCloud.Client.IntegrationTests/ObjectGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -614,5 +614,39 @@ public static CaptchaResult<MTCaptchaTaskResponse> CreateSolution()
};
}
}

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(),
}
};
}
}
}
}
3 changes: 3 additions & 0 deletions CapMonsterCloud.Client.IntegrationTests/Sut.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ public async Task<CaptchaResult<CustomTaskResponse>> SolveAsync(
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()
{
return await _cloudClient.GetBalanceAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,17 @@ private static GetResultTimeouts GetTimeouts(Type type)
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)
}
},
};
}
}
74 changes: 74 additions & 0 deletions CapMonsterCloud.Client/Requests/YidunTaskRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using Newtonsoft.Json;
using System.ComponentModel.DataAnnotations;
using Zennolab.CapMonsterCloud.Responses;

namespace Zennolab.CapMonsterCloud.Requests
{
/// <summary>
/// Yidun (NECaptcha) recognition request.
/// </summary>
/// <example>
/// https://docs.capmonster.cloud/docs/captchas/yidun-task
/// </example>
public sealed class YidunTaskRequest : CaptchaRequestBaseWithProxy<YidunTaskResponse>
{
/// <summary>
/// Recognition task type
/// </summary>
public const string TaskType = "YidunTask";

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

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

/// <summary>
/// The siteKey value found on the page.
/// </summary>
[JsonProperty("websiteKey", Required = Required.Always)]
[StringLength(int.MaxValue, MinimumLength = 1)]
public string WebsiteKey { get; set; }

/// <summary>
/// Browser User-Agent (actual Windows UA recommended).
/// </summary>
[JsonProperty("userAgent")]
public string UserAgent { get; set; }

/// <summary>
/// Full URL of JS loader (Enterprise cases).
/// </summary>
[JsonProperty("yidunGetLib")]
public string YidunGetLib { get; set; }

/// <summary>
/// Custom API server subdomain (Enterprise cases).
/// </summary>
[JsonProperty("yidunApiServerSubdomain")]
public string YidunApiServerSubdomain { get; set; }

/// <summary>
/// Enterprise: current captcha challenge id.
/// </summary>
[JsonProperty("challenge")]
public string Challenge { get; set; }

/// <summary>
/// Enterprise: captcha hash.
/// </summary>
[JsonProperty("hcg")]
public string Hcg { get; set; }

/// <summary>
/// Enterprise: numeric timestamp.
/// </summary>
[JsonProperty("hct")]
public long? Hct { get; set; }
}
}
16 changes: 16 additions & 0 deletions CapMonsterCloud.Client/Responses/YidunTaskResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Newtonsoft.Json;

namespace Zennolab.CapMonsterCloud.Responses
{
/// <summary>
/// Yidun (NECaptcha) recognition response
/// </summary>
public sealed class YidunTaskResponse : CaptchaResponseBase
{
/// <summary>
/// Yidun token to submit.
/// </summary>
[JsonProperty("token")]
public string Value { get; set; }
}
}
Loading