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
47 changes: 47 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,52 @@
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);
}

}
}
39 changes: 39 additions & 0 deletions CapMonsterCloud.Client.IntegrationTests/ObjectGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -546,5 +546,44 @@ 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() }
}
}
}
}
}
};
}

}
}
}
4 changes: 4 additions & 0 deletions CapMonsterCloud.Client.IntegrationTests/Sut.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ public async Task<CaptchaResult<CustomTaskResponse>> SolveAsync(
public async Task<CaptchaResult<DynamicComplexImageTaskResponse>> SolveAsync(
RecognitionComplexImageTaskRequest request) => await _cloudClient.SolveAsync(request);

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


public async Task<decimal> GetBalanceAsync()
{
return await _cloudClient.GetBalanceAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,15 @@ 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)
}
},
};
}
}
41 changes: 41 additions & 0 deletions CapMonsterCloud.Client/Requests/TemuCustomTaskRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using Newtonsoft.Json;
using System.ComponentModel.DataAnnotations;

namespace Zennolab.CapMonsterCloud.Requests
{
/// <summary>
/// Temu CustomTask recognition request.
/// </summary>
/// <example>
/// https://docs.capmonster.cloud/docs/captchas/temu-task
/// </example>
public sealed class TemuCustomTaskRequest : CustomTaskRequestBase
{
/// <inheritdoc/>
public override string Class => "Temu";

/// <summary>
/// Initializes Temu task with required metadata.
/// </summary>
/// <param name="cookie">
/// Cookies string from the page with captcha (document.cookie).
/// </param>
public TemuCustomTaskRequest(string cookie)
{
Metadata = new { cookie };
}

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

// userAgent, Proxy, Domains — уже есть в базе (CustomTaskRequestBase)
}
}
Loading