-
-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
23e2c29
commit de9de47
Showing
18 changed files
with
2,010 additions
and
35 deletions.
There are no files selected for viewing
109 changes: 109 additions & 0 deletions
109
VkNet.Tests/Infrastructure/AuthorizationFormHtmlParserTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Flurl; | ||
using Flurl.Http.Testing; | ||
using Moq.AutoMock; | ||
using NUnit.Framework; | ||
using VkNet.Infrastructure.Authorization.ImplicitFlow; | ||
|
||
namespace VkNet.Tests.Infrastructure | ||
{ | ||
[TestFixture] | ||
public class AuthorizationFormHtmlParserTests | ||
{ | ||
[Test] | ||
public async Task LoginForm() | ||
{ | ||
using (var httpTest = new HttpTest()) | ||
{ | ||
httpTest.RespondWith(ReadHtmlFile("login")); | ||
var mocker = new AutoMocker(); | ||
|
||
var parser = mocker.CreateInstance<AuthorizationFormHtmlParser>(); | ||
var result = await parser.GetFormAsync(new Url("https://m.vk.com/login?act=authcheck&m=442")); | ||
|
||
Assert.NotNull(result); | ||
Assert.AreEqual("post", result.Method); | ||
Assert.AreEqual("https://login.vk.com/?act=login&soft=1&utf8=1", result.Action); | ||
Assert.IsNotEmpty(result.Fields); | ||
} | ||
} | ||
|
||
[Test] | ||
public async Task CaptchaForm() | ||
{ | ||
using (var httpTest = new HttpTest()) | ||
{ | ||
httpTest.RespondWith(ReadHtmlFile("captcha")); | ||
var mocker = new AutoMocker(); | ||
|
||
var parser = mocker.CreateInstance<AuthorizationFormHtmlParser>(); | ||
var result = await parser.GetFormAsync(new Url("https://m.vk.com/login?act=authcheck&m=442")); | ||
|
||
Assert.NotNull(result); | ||
Assert.AreEqual("post", result.Method); | ||
Assert.AreEqual("https://login.vk.com/?act=login&soft=1&utf8=1", result.Action); | ||
Assert.IsNotEmpty(result.Fields); | ||
} | ||
} | ||
|
||
[Test] | ||
public async Task TwoFaForm() | ||
{ | ||
using (var httpTest = new HttpTest()) | ||
{ | ||
httpTest.RespondWith(ReadHtmlFile("twofa")); | ||
var mocker = new AutoMocker(); | ||
|
||
var parser = mocker.CreateInstance<AuthorizationFormHtmlParser>(); | ||
var result = await parser.GetFormAsync(new Url("https://m.vk.com/login?act=authcheck&m=442")); | ||
|
||
Assert.NotNull(result); | ||
Assert.AreEqual("post", result.Method); | ||
Assert.AreEqual("https://m.vk.com/login?act=authcheck_code&hash=1552162040_c98f31a6e83d3c91c1", result.Action); | ||
Assert.IsNotEmpty(result.Fields); | ||
} | ||
} | ||
|
||
[Test] | ||
public async Task ConsentForm() | ||
{ | ||
using (var httpTest = new HttpTest()) | ||
{ | ||
httpTest.RespondWith(ReadHtmlFile("consent")); | ||
var mocker = new AutoMocker(); | ||
|
||
var parser = mocker.CreateInstance<AuthorizationFormHtmlParser>(); | ||
var result = await parser.GetFormAsync(new Url("https://m.vk.com/login?act=authcheck&m=442")); | ||
|
||
Assert.NotNull(result); | ||
Assert.AreEqual("post", result.Method); | ||
Assert.AreEqual("https://login.vk.com/?act=grant_access&client_id=4268118&settings=140492255&redirect_uri=https%3A%2F%2Foauth.vk.com%2Fblank.html&response_type=token&group_ids=&token_type=0&v=&state=123&display=mobile&ip_h=5a4524d95f3521be68&hash=1552162134_98614f6fce5d86d252&https=1", result.Action); | ||
Assert.IsNotEmpty(result.Fields); | ||
} | ||
} | ||
|
||
private string ReadHtmlFile(string fileNameWithoutExtension) | ||
{ | ||
var folders = new List<string> | ||
{ | ||
AppContext.BaseDirectory, | ||
"TestData", | ||
"Authorization", | ||
fileNameWithoutExtension | ||
}; | ||
|
||
var path = Path.Combine(folders.ToArray()) + ".html"; | ||
|
||
if (!File.Exists(path)) | ||
{ | ||
throw new FileNotFoundException(path); | ||
} | ||
|
||
return File.ReadAllText(path, Encoding.UTF8); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.