-
Notifications
You must be signed in to change notification settings - Fork 23
/
ServiceTests.cs
695 lines (539 loc) · 32 KB
/
ServiceTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
using CaptchaSharp.Enums;
using CaptchaSharp.Models;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using CaptchaSharp.Extensions;
using CaptchaSharp.Models.CaptchaOptions;
using CaptchaSharp.Services;
using Xunit;
using Xunit.Abstractions;
namespace CaptchaSharp.Tests;
public class ServiceTests
{
private readonly ServiceFixture _fixture;
private readonly ITestOutputHelper _output;
private const string _captchaImageBase64 = "iVBORw0KGgoAAAANSUhEUgAAAGsAAAAgCAYAAAAVIIajAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAA5/SURBVGhD7Zr3k1VVEsdh8gAlOStLWiwyKLAqsErQMkIVSyqhFAa0VBBYVl1BESUskraUDGK5FpKHXCRByZlVgkOGIQ6TB/6C3vPp9/runTtvHqjgLhY/fOu9ubdvd5/+dvfpc9+UKLhZIPdxb+A+WfcQ7pP1GyD/Rn4hFNz47zX7Hum5IO46WebU7Tp0pxC0+b+yD3Lzc0PfCyIjryBPYfKR9IEiZPkfiPSg3VcE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oBtCxTmTChQV0qE16MXTPd/meiAVn08HalXNlyuhdBlhFnIFC8IeD+8L8Nl+uZoZ/Ng7oUUdboh92HpOLk9brTN3feXCWKpOFne8gK2r8d3JIsgzkSdOiXwq/nl+rkOV20I5d/LWDYsD3RKkk/3VGiabOmMmXKFK1qC24kfZG+R0R4SEBXNH3c4xDOQZ/XTIz4xcnfCrdN1v8rWDRggKEt8Spo85bNsmrNKlm0eJF+375ju270VKEF6pcE6+fC7GCTamLQ+TX273mygD8oXmv1w+6F5UAkPXcDQVu/xv7vgqwg/MH4LYm52/hdkvV7xX2y7hkUyH8AeIrWJFR4fQAAAAAASUVORK5CYII=";
private CaptchaService Service => _fixture.Service;
protected ServiceTests(ServiceFixture fixture, ITestOutputHelper output)
{
this._fixture = fixture;
_output = output;
}
protected static Task ShouldNotBeSupported(Func<Task> method) => Assert.ThrowsAsync<NotSupportedException>(method);
protected async Task BalanceTest()
{
var balance = await Service.GetBalanceAsync();
Assert.True(balance > 0);
_output.WriteLine($"Balance: {balance}");
}
protected async Task ReportImageSolutionTest(bool correct = true)
{
var options = new ImageCaptchaOptions
{
IsPhrase = true,
CaseSensitive = true,
CharacterSet = CharacterSet.NotSpecified,
RequiresCalculation = false,
MinLength = 0,
MaxLength = 0,
CaptchaLanguageGroup = CaptchaLanguageGroup.NotSpecified,
CaptchaLanguage = CaptchaLanguage.NotSpecified,
TextInstructions = ""
};
var solution = await Service.SolveImageCaptchaAsync(
base64: _captchaImageBase64,
options);
await Service.ReportSolutionAsync(
solution.Id, CaptchaType.ImageCaptcha, correct);
Assert.True(true);
}
protected async Task ReportRecaptchaSolutionTest(bool correct = true)
{
var solution = await Service.SolveRecaptchaV2Async(
siteKey: "6LfD3PIbAAAAAJs_eEHvoOl75_83eXSqpPSRFJ_u",
siteUrl: "https://2captcha.com/demo/recaptcha-v2",
dataS: "",
enterprise: false,
invisible: false);
await Service.ReportSolutionAsync(
solution.Id, CaptchaType.ReCaptchaV2, correct);
Assert.True(true);
}
protected async Task TextCaptchaTest()
{
var options = new TextCaptchaOptions
{
CaptchaLanguageGroup = CaptchaLanguageGroup.NotSpecified,
CaptchaLanguage = CaptchaLanguage.NotSpecified
};
var solution = await Service.SolveTextCaptchaAsync(
text: "What is 2+2?",
options);
_output.WriteLine($"Captcha ID: {solution.Id}");
_output.WriteLine($"Response: {solution.Response}");
Assert.Equal("4", solution.Response);
}
protected async Task ImageCaptchaTest()
{
var options = new ImageCaptchaOptions
{
IsPhrase = true,
CaseSensitive = true,
CharacterSet = CharacterSet.NotSpecified,
RequiresCalculation = false,
MinLength = 0,
MaxLength = 0,
CaptchaLanguageGroup = CaptchaLanguageGroup.NotSpecified,
CaptchaLanguage = CaptchaLanguage.NotSpecified,
TextInstructions = ""
};
var solution = await Service.SolveImageCaptchaAsync(
base64: _captchaImageBase64,
options);
_output.WriteLine($"Captcha ID: {solution.Id}");
_output.WriteLine($"Response: {solution.Response}");
Assert.Equal("w68hp", solution.Response.Replace(" ", "").ToLower());
}
private async Task RecaptchaV2Test(SessionParams? sessionParams)
{
var solution = await Service.SolveRecaptchaV2Async(
siteKey: "6LfD3PIbAAAAAJs_eEHvoOl75_83eXSqpPSRFJ_u",
siteUrl: "https://2captcha.com/demo/recaptcha-v2",
dataS: "",
enterprise: false,
invisible: false,
sessionParams);
Assert.NotEqual(string.Empty, solution.Response);
_output.WriteLine($"Captcha ID: {solution.Id}");
_output.WriteLine($"Response: {solution.Response}");
}
protected Task RecaptchaV2Test_NoProxy() => RecaptchaV2Test(null);
protected Task RecaptchaV2Test_WithProxy() => RecaptchaV2Test(_fixture.Config.SessionParams);
private async Task RecaptchaV2InvisibleTest(SessionParams? sessionParams)
{
var solution = await Service.SolveRecaptchaV2Async(
siteKey: "6LdO5_IbAAAAAAeVBL9TClS19NUTt5wswEb3Q7C5",
siteUrl: "https://2captcha.com/demo/recaptcha-v2-invisible",
dataS: "",
enterprise: false,
invisible: true,
sessionParams);
Assert.NotEqual(string.Empty, solution.Response);
_output.WriteLine($"Captcha ID: {solution.Id}");
_output.WriteLine($"Response: {solution.Response}");
}
protected Task RecaptchaV2InvisibleTest_NoProxy() => RecaptchaV2InvisibleTest(null);
protected Task RecaptchaV2InvisibleTest_WithProxy() => RecaptchaV2InvisibleTest(_fixture.Config.SessionParams);
private async Task RecaptchaV2EnterpriseTest(SessionParams? sessionParams)
{
var solution = await Service.SolveRecaptchaV2Async(
siteKey: "6Lf26sUnAAAAAIKLuWNYgRsFUfmI-3Lex3xT5N-s",
siteUrl: "https://2captcha.com/demo/recaptcha-v2-enterprise",
dataS: "",
enterprise: true,
invisible: true,
sessionParams);
Assert.NotEqual(string.Empty, solution.Response);
_output.WriteLine($"Captcha ID: {solution.Id}");
_output.WriteLine($"Response: {solution.Response}");
}
protected Task RecaptchaV2EnterpriseTest_NoProxy() => RecaptchaV2EnterpriseTest(null);
protected Task RecaptchaV2EnterpriseTest_WithProxy() => RecaptchaV2EnterpriseTest(_fixture.Config.SessionParams);
private async Task RecaptchaV3Test(SessionParams? sessionParams)
{
var solution = await Service.SolveRecaptchaV3Async(
siteKey: "6LfB5_IbAAAAAMCtsjEHEHKqcB9iQocwwxTiihJu",
siteUrl: "https://2captcha.com/demo/recaptcha-v3",
action: "demo_action",
minScore: 0.9f,
enterprise: false,
sessionParams);
Assert.NotEqual(string.Empty, solution.Response);
_output.WriteLine($"Captcha ID: {solution.Id}");
_output.WriteLine($"Response: {solution.Response}");
}
protected Task RecaptchaV3Test_NoProxy() => RecaptchaV3Test(null);
protected Task RecaptchaV3Test_WithProxy() => RecaptchaV3Test(_fixture.Config.SessionParams);
private async Task RecaptchaV3EnterpriseTest(SessionParams? sessionParams)
{
var solution = await Service.SolveRecaptchaV3Async(
siteKey: "6Lel38UnAAAAAMRwKj9qLH2Ws4Tf2uTDQCyfgR6b",
siteUrl: "https://2captcha.com/demo/recaptcha-v3-enterprise",
action: "demo_action",
minScore: 0.9f,
enterprise: true,
sessionParams);
Assert.NotEqual(string.Empty, solution.Response);
_output.WriteLine($"Captcha ID: {solution.Id}");
_output.WriteLine($"Response: {solution.Response}");
}
protected Task RecaptchaV3EnterpriseTest_NoProxy() => RecaptchaV3EnterpriseTest(null);
protected Task RecaptchaV3EnterpriseTest_WithProxy() => RecaptchaV3EnterpriseTest(_fixture.Config.SessionParams);
private async Task FunCaptchaTest(SessionParams? sessionParams)
{
var solution = await Service.SolveFuncaptchaAsync(
publicKey: "3EE79F8D-13A6-474B-9278-448EA19F79B3",
serviceUrl: "https://client-api.arkoselabs.com",
siteUrl: "https://www.arkoselabs.com/arkose-matchkey/",
noJs: false,
data: null,
sessionParams);
Assert.NotEqual(string.Empty, solution.Response);
_output.WriteLine($"Captcha ID: {solution.Id}");
_output.WriteLine($"Response: {solution.Response}");
}
protected Task FunCaptchaTest_NoProxy() => FunCaptchaTest(null);
protected Task FunCaptchaTest_WithProxy() => FunCaptchaTest(_fixture.Config.SessionParams);
private async Task HCaptchaTest(SessionParams? sessionParams)
{
var solution = await Service.SolveHCaptchaAsync(
siteKey: "f7de0da3-3303-44e8-ab48-fa32ff8ccc7b",
siteUrl: "https://2captcha.com/demo/hcaptcha",
invisible: false,
enterprisePayload: null,
sessionParams);
Assert.NotEqual(string.Empty, solution.Response);
_output.WriteLine($"Captcha ID: {solution.Id}");
_output.WriteLine($"Response: {solution.Response}");
}
protected Task HCaptchaTest_NoProxy() => HCaptchaTest(null);
protected Task HCaptchaTest_WithProxy() => HCaptchaTest(_fixture.Config.SessionParams);
private async Task KeyCaptchaTest(SessionParams? sessionParams)
{
// Get the required parameters from the page since they are not static
const string siteUrl = "https://www.keycaptcha.com/contact-us/";
using var httpClient = new HttpClient();
using var response = await httpClient.GetAsync(siteUrl);
var pageSource = await response.Content.ReadAsStringAsync();
var userId = Regex.Match(pageSource, "var s_s_c_user_id = '([^']*)'").Groups[1].Value;
var sessionId = Regex.Match(pageSource, "var s_s_c_session_id = '([^']*)'").Groups[1].Value;
var webServerSign1 = Regex.Match(pageSource, "var s_s_c_web_server_sign = '([^']*)'").Groups[1].Value;
var webServerSign2 = Regex.Match(pageSource, "var s_s_c_web_server_sign2 = '([^']*)'").Groups[1].Value;
var solution = await Service.SolveKeyCaptchaAsync(
userId,
sessionId,
webServerSign1,
webServerSign2,
siteUrl,
sessionParams);
Assert.NotEqual(string.Empty, solution.Response);
_output.WriteLine($"Captcha ID: {solution.Id}");
_output.WriteLine($"Response: {solution.Response}");
}
protected Task KeyCaptchaTest_NoProxy() => KeyCaptchaTest(null);
protected Task KeyCaptchaTest_WithProxy() => KeyCaptchaTest(_fixture.Config.SessionParams);
private async Task GeeTestTest(SessionParams? sessionParams)
{
// Get the required parameters from the page since they are not static
var unixTime = DateTimeOffset.Now.ToUnixTimeMilliseconds();
var siteUrl = $"https://www.geetest.com/demo/gt/register-enFullpage-official?t={unixTime}";
using var httpClient = new HttpClient();
using var response = await httpClient.GetAsync(siteUrl);
var pageSource = await response.Content.ReadAsStringAsync();
var obj = JObject.Parse(pageSource);
var gt = obj.Value<string>("gt")!;
var challenge = obj.Value<string>("challenge")!;
var solution = await Service.SolveGeeTestAsync(
gt,
challenge,
siteUrl,
apiServer: "api.geetest.com",
sessionParams);
Assert.NotEqual("", solution.Challenge);
Assert.NotEqual("", solution.SecCode);
Assert.NotEqual("", solution.Validate);
_output.WriteLine($"Captcha ID: {solution.Id}");
_output.WriteLine($"Challenge: {solution.Challenge}");
_output.WriteLine($"SecCode: {solution.SecCode}");
_output.WriteLine($"Validate: {solution.Validate}");
}
protected Task GeeTestTest_NoProxy() => GeeTestTest(null);
protected Task GeeTestTest_WithProxy() => GeeTestTest(_fixture.Config.SessionParams);
private async Task CapyTest(SessionParams? sessionParams)
{
var solution = await Service.SolveCapyAsync(
siteKey: "PUZZLE_Cme4hZLjuZRMYC3uh14C52D3uNms5w",
siteUrl: $"{"https"}://www.capy.me/account/signin",
sessionParams);
Assert.NotEqual(string.Empty, solution.ChallengeKey);
Assert.NotEqual(string.Empty, solution.CaptchaKey);
Assert.NotEqual(string.Empty, solution.Answer);
_output.WriteLine($"Captcha ID: {solution.Id}");
_output.WriteLine($"ChallengeKey: {solution.ChallengeKey}");
_output.WriteLine($"CaptchaKey: {solution.CaptchaKey}");
_output.WriteLine($"Answer: {solution.Answer}");
}
protected Task CapyTest_NoProxy() => CapyTest(null);
protected Task CapyTest_WithProxy() => CapyTest(_fixture.Config.SessionParams);
// Proxy and User-Agent required
private async Task DataDomeTest(SessionParams sessionParams)
{
const string site = "https://antoinevastel.com/bots/datadome";
// If it doesn't work, try a few times until it triggers
// the captcha
var cookieContainer = new CookieContainer();
using var httpClientHandler = new HttpClientHandler();
httpClientHandler.UseCookies = true;
httpClientHandler.CookieContainer = cookieContainer;
using var httpClient = new HttpClient(httpClientHandler);
if (string.IsNullOrEmpty(sessionParams.UserAgent))
{
throw new ArgumentException("User-Agent is required");
}
// The User-Agent must be the same as the one used to get the page
httpClient.DefaultRequestHeaders.Add("User-Agent", sessionParams.UserAgent);
using var response = await httpClient.GetAsync(site);
var pageSource = await response.Content.ReadAsStringAsync();
var host = Regex.Match(pageSource, "'host':'([^']*)'").Groups[1].Value;
var initialCid = Regex.Match(pageSource, "'cid':'([^']*)'").Groups[1].Value;
var t = Regex.Match(pageSource, "'t':'([^']*)'").Groups[1].Value;
var s = Regex.Match(pageSource, @"'s':(\d+)").Groups[1].Value;
var e = Regex.Match(pageSource, "'e':'([^']*)'").Groups[1].Value;
var hsh = Regex.Match(pageSource, "'hsh':'([^']*)'").Groups[1].Value;
// Get cid from "datadome" cookie
var cid = cookieContainer.GetCookies(new Uri(site))["datadome"]?.Value;
sessionParams.Cookies = new Dictionary<string, string>
{
["datadome"] = cid!
};
var captchaUrl =
$"https://{host}/captcha/?initialCid={WebUtility.UrlEncode(initialCid)}&hash={hsh}&cid={cid}&t={t}&referer={WebUtility.UrlEncode(site)}&s={s}&e={e}&dm=cd";
var solution = await Service.SolveDataDomeAsync(
siteUrl: site,
captchaUrl: captchaUrl,
sessionParams);
Assert.NotEqual(string.Empty, solution.Response);
_output.WriteLine($"Captcha ID: {solution.Id}");
_output.WriteLine($"Response: {solution.Response}");
}
protected Task DataDomeTest_WithProxy() => DataDomeTest(_fixture.Config.SessionParams);
private async Task CloudflareTurnstileTest(SessionParams? sessionParams)
{
var solution = await Service.SolveCloudflareTurnstileAsync(
siteKey: "0x4AAAAAAAVrOwQWPlm3Bnr5",
siteUrl: "https://2captcha.com/demo/cloudflare-turnstile",
sessionParams: sessionParams);
Assert.NotEqual(string.Empty, solution.Response);
_output.WriteLine($"Captcha ID: {solution.Id}");
_output.WriteLine($"Response: {solution.Response}");
_output.WriteLine($"User-Agent: {solution.UserAgent}");
}
protected Task CloudflareTurnstileTest_NoProxy() => CloudflareTurnstileTest(new SessionParams
{
// User-Agent required
UserAgent = _fixture.Config.SessionParams.UserAgent
});
protected Task CloudflareTurnstileTest_WithProxy() => CloudflareTurnstileTest(_fixture.Config.SessionParams);
private async Task LeminCroppedTest(SessionParams? sessionParams)
{
var solution = await Service.SolveLeminCroppedAsync(
captchaId: "CROPPED_3dfdd5c_d1872b526b794d83ba3b365eb15a200b",
siteUrl: "https://2captcha.com/demo/lemin",
sessionParams: sessionParams);
Assert.NotEqual(string.Empty, solution.Answer);
Assert.NotEqual(string.Empty, solution.ChallengeId);
_output.WriteLine($"Captcha ID: {solution.Id}");
_output.WriteLine($"Answer: {solution.Answer}");
_output.WriteLine($"Challenge ID: {solution.ChallengeId}");
}
protected Task LeminCroppedTest_NoProxy() => LeminCroppedTest(null);
protected Task LeminCroppedTest_WithProxy() => LeminCroppedTest(_fixture.Config.SessionParams);
private async Task AmazonWafTest(SessionParams? sessionParams)
{
using var httpClient = new HttpClient();
using var response = await httpClient.GetAsync("https://nopecha.com/captcha/awscaptcha");
var pageSource = await response.Content.ReadAsStringAsync();
var captchaPage = Regex.Match(pageSource, "<iframe src=\"([^\"]+)").Groups[1].Value;
using var captchaResponse = await httpClient.GetAsync(captchaPage);
var captchaSource = await captchaResponse.Content.ReadAsStringAsync();
var siteKey = Regex.Match(captchaSource, "\"key\":\"([^\"]+)").Groups[1].Value;
var iv = Regex.Match(captchaSource, "\"iv\":\"([^\"]+)").Groups[1].Value;
var context = Regex.Match(captchaSource, "\"context\":\"([^\"]+)").Groups[1].Value;
var challengeScript = Regex.Match(captchaSource, "src=\"([^\"]+challenge\\.js)").Groups[1].Value;
var captchaScript = Regex.Match(captchaSource, "src=\"([^\"]+captcha\\.js)").Groups[1].Value;
var solution = await Service.SolveAmazonWafAsync(
siteKey: siteKey,
siteUrl: "https://nopecha.com/captcha/awscaptcha",
iv: iv,
context: context,
challengeScript: challengeScript,
captchaScript: captchaScript,
sessionParams: sessionParams);
Assert.NotEqual(string.Empty, solution.Response);
_output.WriteLine($"Captcha ID: {solution.Id}");
_output.WriteLine($"Response: {solution.Response}");
}
protected Task AmazonWafTest_NoProxy() => AmazonWafTest(null);
protected Task AmazonWafTest_WithProxy() => AmazonWafTest(_fixture.Config.SessionParams);
private async Task CyberSiAraTest(SessionParams? sessionParams)
{
var solution = await Service.SolveCyberSiAraAsync(
masterUrlId: "ABEBCAFBAAEDADFCBCCBEBAFCDDBBFEF",
siteUrl: "https://mycybersiara.com/login",
sessionParams: sessionParams);
Assert.NotEqual(string.Empty, solution.Response);
_output.WriteLine($"Captcha ID: {solution.Id}");
_output.WriteLine($"Response: {solution.Response}");
}
protected Task CyberSiAraTest_NoProxy() => CyberSiAraTest(new SessionParams
{
// User-Agent required
UserAgent = _fixture.Config.SessionParams.UserAgent
});
protected Task CyberSiAraTest_WithProxy() => CyberSiAraTest(_fixture.Config.SessionParams);
private async Task MtCaptchaTest(SessionParams? sessionParams)
{
var solution = await Service.SolveMtCaptchaAsync(
siteKey: "MTPublic-KzqLY1cKH",
siteUrl: "https://2captcha.com/demo/mtcaptcha",
sessionParams: sessionParams);
Assert.NotEqual(string.Empty, solution.Response);
_output.WriteLine($"Captcha ID: {solution.Id}");
_output.WriteLine($"Response: {solution.Response}");
}
protected Task MtCaptchaTest_NoProxy() => MtCaptchaTest(null);
protected Task MtCaptchaTest_WithProxy() => MtCaptchaTest(_fixture.Config.SessionParams);
private async Task CutCaptchaTest(SessionParams? sessionParams)
{
var solution = await Service.SolveCutCaptchaAsync(
siteUrl: "https://filecrypt.co/Container/BB072CC14C.html",
miseryKey: "a46cd428f9cd7b965f6dcb84741e733769725550",
apiKey: "SAs61IAI",
sessionParams: sessionParams);
Assert.NotEqual(string.Empty, solution.Response);
_output.WriteLine($"Captcha ID: {solution.Id}");
_output.WriteLine($"Response: {solution.Response}");
}
protected Task CutCaptchaTest_NoProxy() => CutCaptchaTest(null);
protected Task CutCaptchaTest_WithProxy() => CutCaptchaTest(_fixture.Config.SessionParams);
private async Task FriendlyCaptchaTest(SessionParams? sessionParams)
{
var solution = await Service.SolveFriendlyCaptchaAsync(
siteKey: "FCMGEMUD2K3JJ36P",
siteUrl: "https://friendlycaptcha.com/signup/account/starter/",
sessionParams: sessionParams);
Assert.NotEqual(string.Empty, solution.Response);
_output.WriteLine($"Captcha ID: {solution.Id}");
_output.WriteLine($"Response: {solution.Response}");
}
protected Task FriendlyCaptchaTest_NoProxy() => FriendlyCaptchaTest(null);
protected Task FriendlyCaptchaTest_WithProxy() => FriendlyCaptchaTest(_fixture.Config.SessionParams);
private async Task AtbCaptchaTest(SessionParams? sessionParams)
{
var solution = await Service.SolveAtbCaptchaAsync(
appId: "af25e409b33d722a95e56a230ff8771c",
apiServer: "https://cap.aisecurius.com",
siteUrl: "https://renslider.com",
sessionParams: sessionParams);
Assert.NotEqual(string.Empty, solution.Response);
_output.WriteLine($"Captcha ID: {solution.Id}");
_output.WriteLine($"Response: {solution.Response}");
}
protected Task AtbCaptchaTest_NoProxy() => AtbCaptchaTest(null);
protected Task AtbCaptchaTest_WithProxy() => AtbCaptchaTest(_fixture.Config.SessionParams);
private async Task TencentCaptchaTest(SessionParams? sessionParams)
{
var solution = await Service.SolveTencentCaptchaAsync(
appId: "2009899766",
siteUrl: "https://www.tencentcloud.com/account/register",
sessionParams: sessionParams);
Assert.NotEqual(string.Empty, solution.Ticket);
Assert.NotEqual(string.Empty, solution.RandomString);
_output.WriteLine($"Captcha ID: {solution.Id}");
_output.WriteLine($"AppId: {solution.AppId}");
_output.WriteLine($"Ticket: {solution.Ticket}");
_output.WriteLine($"ReturnCode: {solution.ReturnCode}");
_output.WriteLine($"RandomString: {solution.RandomString}");
}
protected Task TencentCaptchaTest_NoProxy() => TencentCaptchaTest(null);
protected Task TencentCaptchaTest_WithProxy() => TencentCaptchaTest(_fixture.Config.SessionParams);
protected async Task AudioCaptchaTest()
{
using var httpClient = new HttpClient();
using var response = await httpClient.GetAsync(
"https://audio-samples.github.io/samples/mp3/ted_speakers/BillGates/sample-1.mp3");
var audioBytes = await response.Content.ReadAsByteArrayAsync();
var solution = await Service.SolveAudioCaptchaAsync(
base64: Convert.ToBase64String(audioBytes),
options: new AudioCaptchaOptions
{
CaptchaLanguage = CaptchaLanguage.English,
});
Assert.Contains("phrase", solution.Response.ToLower());
_output.WriteLine($"Captcha ID: {solution.Id}");
_output.WriteLine($"Response: {solution.Response}");
}
private async Task RecaptchaMobileTest(SessionParams? sessionParams)
{
var solution = await Service.SolveRecaptchaMobileAsync(
appPackageName: "",
appKey: "",
appAction: "login",
sessionParams: sessionParams);
Assert.NotEqual(string.Empty, solution.Response);
_output.WriteLine($"Captcha ID: {solution.Id}");
_output.WriteLine($"Response: {solution.Response}");
}
protected Task RecaptchaMobileTest_NoProxy() => RecaptchaMobileTest(null);
protected Task RecaptchaMobileTest_WithProxy() => RecaptchaMobileTest(_fixture.Config.SessionParams);
private async Task GeeTestV4Test(SessionParams? sessionParams)
{
var solution = await Service.SolveGeeTestV4Async(
captchaId: "42977dc9-a215-4b09-aa14-945ef310d829",
siteUrl: "https://2captcha.com/demo/geetest-v4",
sessionParams: sessionParams);
Assert.NotEqual(string.Empty, solution.CaptchaId);
Assert.NotEqual(string.Empty, solution.LotNumber);
Assert.NotEqual(string.Empty, solution.PassToken);
Assert.NotEqual(string.Empty, solution.GenTime);
Assert.NotEqual(string.Empty, solution.CaptchaOutput);
_output.WriteLine($"Captcha ID: {solution.Id}");
_output.WriteLine($"GeeTest Captcha ID: {solution.CaptchaId}");
_output.WriteLine($"Lot Number: {solution.LotNumber}");
_output.WriteLine($"Pass Token: {solution.PassToken}");
_output.WriteLine($"Gen Time: {solution.GenTime}");
_output.WriteLine($"Captcha Output: {solution.CaptchaOutput}");
}
protected Task GeeTestV4Test_NoProxy() => GeeTestV4Test(null);
protected Task GeeTestV4Test_WithProxy() => GeeTestV4Test(_fixture.Config.SessionParams);
private async Task CloudflareChallengePageTest(SessionParams sessionParams)
{
var pageUrl = "https://2captcha.com/demo/cloudflare-turnstile-challenge";
var proxy = sessionParams.Proxy;
if (string.IsNullOrEmpty(sessionParams.UserAgent))
{
throw new ArgumentNullException(
nameof(sessionParams), "Solving Cloudflare challenges requires a User-Agent");
}
if (string.IsNullOrEmpty(proxy?.Host))
{
throw new ArgumentNullException(
nameof(sessionParams), "Solving Cloudflare challenges requires a proxy");
}
var webProxy = new WebProxy($"{proxy.Type.ToString().ToLower()}://{proxy.Host}:{proxy.Port}");
if (proxy.RequiresAuthentication)
{
webProxy.Credentials = new NetworkCredential(proxy.Username, proxy.Password);
}
using var httpClientHandler = new HttpClientHandler();
httpClientHandler.Proxy = webProxy;
httpClientHandler.UseProxy = true;
using var httpClient = new HttpClient(httpClientHandler);
httpClient.DefaultRequestHeaders.Add("User-Agent", sessionParams.UserAgent);
var response = await httpClient.GetAsync(pageUrl);
var pageHtml = await response.Content.ReadAsStringAsync();
var solution = await Service.SolveCloudflareChallengePageAsync(
siteUrl: pageUrl,
pageHtml: pageHtml,
sessionParams: sessionParams);
Assert.NotEqual(string.Empty, solution.Response);
_output.WriteLine($"Captcha ID: {solution.Id}");
_output.WriteLine($"Response: {solution.Response}");
}
protected Task CloudflareChallengePageTest_WithProxy() => CloudflareChallengePageTest(_fixture.Config.SessionParams);
}