Exemplo n.º 1
0
        public void Test_WhenFileNotExists_Throws_CredentialUnavailableException()
        {
            var credential = new TokenFileCredential();
            var exception  = Assert.ThrowsException <CredentialUnavailableException>(() =>
                                                                                     credential.GetToken(new TokenRequestContext(new string[] { _azureQuantumScope }), CancellationToken.None));

            Assert.AreEqual($"Token file at {_tokenFilePath} does not exist.", exception.Message);
        }
Exemplo n.º 2
0
        public void Test_WhenFileNotSet_Throws_CredentialUnavailableException()
        {
            Environment.SetEnvironmentVariable("AZURE_QUANTUM_TOKEN_FILE", null);
            var credential = new TokenFileCredential();

            var exception = Assert.ThrowsException <CredentialUnavailableException>(() =>
                                                                                    credential.GetToken(new TokenRequestContext(new string[] { _azureQuantumScope }), CancellationToken.None));

            Assert.AreEqual("Token file location not set.", exception.Message);
        }
Exemplo n.º 3
0
        public void Test_WhenMissingExpiresOnField_Throws_CredentialUnavailableException()
        {
            string content = @"{
              ""access_token"": ""fake_token""
            }";

            var credential = new TokenFileCredential(new FileSystemTestImpl(content));
            var exception  = Assert.ThrowsException <CredentialUnavailableException>(() =>
                                                                                     credential.GetToken(new TokenRequestContext(new string[] { _azureQuantumScope }), CancellationToken.None));

            Assert.AreEqual("Failed to parse token file: Missing expected value: 'expires_on'", exception.Message);
        }
Exemplo n.º 4
0
        public void Test_WhenExpiredToken_Throws_CredentialUnavailableException()
        {
            string content = @"{
              ""access_token"": ""fake_token"",
              ""expires_on"": 1628543125086
            }";

            var credential = new TokenFileCredential(new FileSystemTestImpl(content));
            var exception  = Assert.ThrowsException <CredentialUnavailableException>(() =>
                                                                                     credential.GetToken(new TokenRequestContext(new string[] { _azureQuantumScope }), CancellationToken.None));

            Assert.AreEqual("Token already expired at 2021-08-09 21:05:25Z", exception.Message);
        }
Exemplo n.º 5
0
        public void Test_WhenInvalidJson_Throws_CredentialUnavailableException()
        {
            string notJson    = "invalid json";
            var    credential = new TokenFileCredential(new FileSystemTestImpl(notJson));
            var    exception  = Assert.ThrowsException <CredentialUnavailableException>(() =>
                                                                                        credential.GetToken(new TokenRequestContext(new string[] { _azureQuantumScope }), CancellationToken.None));

            Assert.AreEqual("Failed to parse token file: Invalid JSON.", exception.Message);
        }