mirror of
https://github.com/vknet/vk.git
synced 2026-07-22 22:33:28 +00:00
130 lines
No EOL
3.2 KiB
C#
130 lines
No EOL
3.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using AwesomeAssertions;
|
|
using VkNet.Infrastructure.Authorization.ImplicitFlow;
|
|
using Xunit;
|
|
|
|
namespace VkNet.Tests.Infrastructure;
|
|
|
|
public class AuthorizationFormHtmlParserTests : BaseTest
|
|
{
|
|
[Fact(DisplayName = "Login form")]
|
|
public async Task LoginForm()
|
|
{
|
|
Url = "https://m.vk.ru/login?act=authcheck&m=442";
|
|
ReadHtmlFile("login");
|
|
|
|
var parser = Mocker.CreateInstance<AuthorizationFormHtmlParser>();
|
|
var result = await parser.GetFormAsync(new("https://m.vk.ru/login?act=authcheck&m=442"));
|
|
|
|
result.Should()
|
|
.NotBeNull();
|
|
|
|
result.Method.Should()
|
|
.Be("post");
|
|
|
|
result.Action.Should()
|
|
.Be("https://login.vk.ru/?act=login&soft=1&utf8=1");
|
|
|
|
result.Fields.Should()
|
|
.NotBeEmpty();
|
|
}
|
|
|
|
[Fact(DisplayName = "Captcha form")]
|
|
public async Task CaptchaForm()
|
|
{
|
|
Url = "https://m.vk.ru/login?act=authcheck&m=442";
|
|
ReadHtmlFile("captcha");
|
|
|
|
var parser = Mocker.CreateInstance<AuthorizationFormHtmlParser>();
|
|
var result = await parser.GetFormAsync(new("https://m.vk.ru/login?act=authcheck&m=442"));
|
|
|
|
result.Should()
|
|
.NotBeNull();
|
|
|
|
result.Method.Should()
|
|
.Be("post");
|
|
|
|
result.Action.Should()
|
|
.Be("https://login.vk.ru/?act=login&soft=1&utf8=1");
|
|
|
|
result.UrlToCaptcha.Should()
|
|
.NotBeNull();
|
|
|
|
var isCaptchaIndicated = result.UrlToCaptcha.Contains("captcha.php");
|
|
|
|
isCaptchaIndicated.Should()
|
|
.BeTrue();
|
|
|
|
result.Fields.Should()
|
|
.NotBeEmpty();
|
|
}
|
|
|
|
[Fact(DisplayName = "Two fa form")]
|
|
public async Task TwoFaForm()
|
|
{
|
|
Url = "https://m.vk.ru/login?act=authcheck&m=442";
|
|
ReadHtmlFile("twofa");
|
|
|
|
var parser = Mocker.CreateInstance<AuthorizationFormHtmlParser>();
|
|
var result = await parser.GetFormAsync(new("https://m.vk.ru/login?act=authcheck&m=442"));
|
|
|
|
result.Should()
|
|
.NotBeNull();
|
|
|
|
result.Method.Should()
|
|
.Be("post");
|
|
|
|
result.Action.Should()
|
|
.Be("https://m.vk.ru/login?act=authcheck_code&hash=1552162040_c98f31a6e83d3c91c1");
|
|
|
|
result.Fields.Should()
|
|
.NotBeEmpty();
|
|
}
|
|
|
|
[Fact(DisplayName = "Consent form")]
|
|
public async Task ConsentForm()
|
|
{
|
|
Url = "https://m.vk.ru/login?act=authcheck&m=442";
|
|
ReadHtmlFile("consent");
|
|
|
|
var parser = Mocker.CreateInstance<AuthorizationFormHtmlParser>();
|
|
var result = await parser.GetFormAsync(new("https://m.vk.ru/login?act=authcheck&m=442"));
|
|
|
|
result.Should()
|
|
.NotBeNull();
|
|
|
|
result.Method.Should()
|
|
.Be("post");
|
|
|
|
result.Action.Should()
|
|
.Be(
|
|
"https://login.vk.ru/?act=grant_access&client_id=4268118&settings=140492255&redirect_uri=https%3A%2F%2Foauth.vk.ru%2Fblank.html&response_type=token&group_ids=&token_type=0&v=&state=123&display=mobile&ip_h=5a4524d95f3521be68&hash=1552162134_98614f6fce5d86d252&https=1");
|
|
|
|
result.Fields.Should()
|
|
.NotBeEmpty();
|
|
}
|
|
|
|
private void 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);
|
|
}
|
|
|
|
Json = File.ReadAllText(path, Encoding.UTF8);
|
|
}
|
|
} |