<commit_before>﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Configuration;
using System.IO;

namespace Authy.Net.Tests
{
    /// <remarks>
    /// 
    /// Important!!!
    /// 
    /// These tests won't pass unless you add a file Called ApiKey.txt to the root of the test project.
    /// Once created add a single line containing a sandbox api key.
    /// You can obtain such a key from the dashboard in your Authy account after you have created an application.
    /// 
    /// </remarks>
    [TestClass]
    public class ClientTests
    {
        const string badApiKey = "<KEY>";

        [TestMethod]
        public void Registration_Success()
        {
            var client = this.GoodApiKeyClient;
            var result = client.RegisterUser("<EMAIL>", "123-456-7890");
            Assert.AreEqual(AuthyStatus.Success, result.Status);
            Assert.IsNotNull(result.UserId);
            Assert.AreNotEqual(string.Empty, result.UserId);
        }

        [TestMethod]
        public void Registration_BadEmail()
        {
            var client = this.GoodApiKeyClient;
            var result = client.RegisterUser("test.<EMAIL>", "123-456-7891");
            Assert.AreEqual(AuthyStatus.BadRequest, result.Status);
            Assert.IsFalse((result.ErrorFields & AuthyErrorFields.Cellphone) == AuthyErrorFields.Cellphone);
            Assert.IsTrue((result.ErrorFields & AuthyErrorFields.Email) == AuthyErrorFields.Email);
        }

        [TestMethod]
        public void Registration_BadPhoneNumber()
        {
            var client = this.GoodApiKeyClient;
            var result = client.RegisterUser("<EMAIL>", "aaa-456-7890");
            Assert.AreEqual(AuthyStatus.BadRequest, result.Status);
            Assert.IsTrue((result.ErrorFields & AuthyErrorFields.Cellphone) == AuthyErrorFields.Cellphone);
            Assert.IsFalse((result.ErrorFields & AuthyErrorFields.Email) == AuthyErrorFields.Email);
        }

        [TestMethod]
        public void Registration_BadEmailAndPhoneNumber()
        {
            var client = this.GoodApiKeyClient;
            var result = client.RegisterUser("<EMAIL>", "aaa-456-7890");
            Assert.AreEqual(AuthyStatus.BadRequest, result.Status);
            Assert.IsTrue((result.ErrorFields & AuthyErrorFields.Cellphone) == AuthyErrorFields.Cellphone);
            Assert.IsTrue((result.ErrorFields & AuthyErrorFields.Email) == AuthyErrorFields.Email);
        }

        [TestMethod]
        public void Registration_BadApiKey()
        {
            var client = new AuthyClient(badApiKey, true);
            var result = client.RegisterUser("<EMAIL>", "123-456-7890");
            Assert.AreEqual(AuthyStatus.Unauthorized, result.Status);
            Assert.IsTrue((result.ErrorFields & AuthyErrorFields.ApiKey) == AuthyErrorFields.ApiKey);
        }

        [TestMethod]
        public void Verification_Success()
        {
            var client = this.GoodApiKeyClient;
            var result = client.VerifyToken("1", "0<PASSWORD>");
            Assert.AreEqual(AuthyStatus.Success, result.Status);
        }

        [TestMethod]
        public void Verification_BadToken()
        {
            // duplicate a succesful registration to get a valid user id
            var client = this.GoodApiKeyClient;
            var registrationResult = client.RegisterUser("<EMAIL>", "123-456-7890");
            Assert.AreEqual(AuthyStatus.Success, registrationResult.Status);
            Assert.IsNotNull(registrationResult.UserId);
            Assert.AreNotEqual(string.Empty, registrationResult.UserId);

            // now for the actual bad token test
            var verifyResult = client.VerifyToken(registrationResult.UserId, "<PASSWORD>");
            Assert.AreEqual(AuthyStatus.Unauthorized, verifyResult.Status);
            Assert.IsTrue((verifyResult.ErrorFields & AuthyErrorFields.Token) == AuthyErrorFields.Token);
        }

        [TestMethod]
        public void Verification_BadApiKey()
        {
            var client = new AuthyClient(badApiKey, true);
            var result = client.VerifyToken("1", "0<PASSWORD>");

            Assert.AreEqual(AuthyStatus.Unauthorized, result.Status);
            Assert.IsTrue((result.ErrorFields & AuthyErrorFields.ApiKey) == AuthyErrorFields.ApiKey);
        }

        [TestMethod]
        public void Verification_InvalidUser()
        {
            var client = this.GoodApiKeyClient;
            var result = client.VerifyToken("9<PASSWORD>", "<PASSWORD>");
            Assert.AreEqual(AuthyStatus.Unauthorized, result.Status);
            Assert.IsTrue((result.ErrorFields & AuthyErrorFields.User) == AuthyErrorFields.User);
        }

        private AuthyClient GoodApiKeyClient
        {
            get { return new AuthyClient(ApiKey.Value, true); }
        }

        private Lazy<string> ApiKey = new Lazy<string>(() => File.ReadAllText("ApiKey.txt"));
    }
}<commit_msg>remove dependency on the ApiKey file<commit_after>﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Configuration;
using System.IO;

namespace Authy.Net.Tests
{
    /// <remarks>
    /// 
    /// Important!!!
    /// 
    /// These tests won't pass unless you set the api key below.
    /// You can obtain such a key from the dashboard in your Authy account after you have created an application.
    /// 
    /// </remarks>
    [TestClass]
    public class ClientTests
    {
		/// <summary>
		/// Api Key. This must be set from your own account
		/// </summary>
		const string goodApiKey = "dummy";
        const string badApiKey = "<KEY>";

        [TestMethod]
        public void Registration_Success()
        {
            var client = this.GoodApiKeyClient;
            var result = client.RegisterUser("<EMAIL>", "123-456-7890");
            Assert.AreEqual(AuthyStatus.Success, result.Status);
            Assert.IsNotNull(result.UserId);
            Assert.AreNotEqual(string.Empty, result.UserId);
        }

        [TestMethod]
        public void Registration_BadEmail()
        {
            var client = this.GoodApiKeyClient;
            var result = client.RegisterUser("test.<EMAIL>", "123-456-7891");
            Assert.AreEqual(AuthyStatus.BadRequest, result.Status);
            Assert.IsFalse((result.ErrorFields & AuthyErrorFields.Cellphone) == AuthyErrorFields.Cellphone);
            Assert.IsTrue((result.ErrorFields & AuthyErrorFields.Email) == AuthyErrorFields.Email);
        }

        [TestMethod]
        public void Registration_BadPhoneNumber()
        {
            var client = this.GoodApiKeyClient;
            var result = client.RegisterUser("<EMAIL>", "aaa-456-7890");
            Assert.AreEqual(AuthyStatus.BadRequest, result.Status);
            Assert.IsTrue((result.ErrorFields & AuthyErrorFields.Cellphone) == AuthyErrorFields.Cellphone);
            Assert.IsFalse((result.ErrorFields & AuthyErrorFields.Email) == AuthyErrorFields.Email);
        }

        [TestMethod]
        public void Registration_BadEmailAndPhoneNumber()
        {
            var client = this.GoodApiKeyClient;
            var result = client.RegisterUser("test.com", "aaa-456-7890");
            Assert.AreEqual(AuthyStatus.BadRequest, result.Status);
            Assert.IsTrue((result.ErrorFields & AuthyErrorFields.Cellphone) == AuthyErrorFields.Cellphone);
            Assert.IsTrue((result.ErrorFields & AuthyErrorFields.Email) == AuthyErrorFields.Email);
        }

        [TestMethod]
        public void Registration_BadApiKey()
        {
            var client = new AuthyClient(badApiKey, true);
            var result = client.RegisterUser("<EMAIL>", "123-456-7890");
            Assert.AreEqual(AuthyStatus.Unauthorized, result.Status);
            Assert.IsTrue((result.ErrorFields & AuthyErrorFields.ApiKey) == AuthyErrorFields.ApiKey);
        }

        [TestMethod]
        public void Verification_Success()
        {
            var client = this.GoodApiKeyClient;
            var result = client.VerifyToken("1", "0000000");
            Assert.AreEqual(AuthyStatus.Success, result.Status);
        }

        [TestMethod]
        public void Verification_BadToken()
        {
            // duplicate a succesful registration to get a valid user id
            var client = this.GoodApiKeyClient;
            var registrationResult = client.RegisterUser("<EMAIL>", "123-456-7890");
            Assert.AreEqual(AuthyStatus.Success, registrationResult.Status);
            Assert.IsNotNull(registrationResult.UserId);
            Assert.AreNotEqual(string.Empty, registrationResult.UserId);

            // now for the actual bad token test
            var verifyResult = client.VerifyToken(registrationResult.UserId, "<PASSWORD>");
            Assert.AreEqual(AuthyStatus.Unauthorized, verifyResult.Status);
            Assert.IsTrue((verifyResult.ErrorFields & AuthyErrorFields.Token) == AuthyErrorFields.Token);
        }

        [TestMethod]
        public void Verification_BadApiKey()
        {
            var client = new AuthyClient(badApiKey, true);
            var result = client.VerifyToken("1", "<PASSWORD>");

            Assert.AreEqual(AuthyStatus.Unauthorized, result.Status);
            Assert.IsTrue((result.ErrorFields & AuthyErrorFields.ApiKey) == AuthyErrorFields.ApiKey);
        }

        [TestMethod]
        public void Verification_InvalidUser()
        {
            var client = this.GoodApiKeyClient;
            var result = client.VerifyToken("<PASSWORD>", "<PASSWORD>");
            Assert.AreEqual(AuthyStatus.Unauthorized, result.Status);
            Assert.IsTrue((result.ErrorFields & AuthyErrorFields.User) == AuthyErrorFields.User);
        }

        private AuthyClient GoodApiKeyClient
        {
            get { return new AuthyClient(goodApiKey, true); }
        }
    }
}
{'fraction_non_alphanumeric': 0.10683204961488446, 'fraction_numerical': 0.012203661098329498, 'mean_word_length': 2.433379120879121, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5692090', 'n_tokens_mistral': 2746, 'n_tokens_neox': 2640, 'n_words': 535}