Skip to content
Merged

v109 #1963

Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixing OAuth1 tests
  • Loading branch information
alexeyzimarev committed Nov 16, 2022
commit a4473c35fc335eecf59eca2db3c340bc7ee6cab8
96 changes: 20 additions & 76 deletions test/RestSharp.Tests/OAuth1AuthenticatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,81 +70,25 @@ public void Authenticate_ShouldAddSignatureToRequestAsSeparateParameters_OnUrlOr

// Assert
var parameters = request.Parameters;

Assert.NotNull(
parameters.FirstOrDefault(
x => x.Type == ParameterType.GetOrPost &&
x.Name == "x_auth_username" &&
(string)x.Value == "ClientUsername" &&
x.ContentType == null
)
);

Assert.NotNull(
parameters.FirstOrDefault(
x => x.Type == ParameterType.GetOrPost &&
x.Name == "x_auth_password" &&
(string)x.Value == "ClientPassword" &&
x.ContentType == null
)
);

Assert.NotNull(
parameters.FirstOrDefault(
x => x.Type == ParameterType.GetOrPost && x.Name == "x_auth_mode" && (string)x.Value == "client_auth" && x.ContentType == null
)
);

Assert.NotNull(
parameters.FirstOrDefault(
x => x.Type == ParameterType.GetOrPost &&
x.Name == "oauth_consumer_key" &&
(string)x.Value == "ConsumerKey" &&
x.ContentType == null
)
);

Assert.NotNull(
parameters.FirstOrDefault(
x => x.Type == ParameterType.GetOrPost &&
x.Name == "oauth_signature" &&
!string.IsNullOrWhiteSpace((string)x.Value) &&
x.ContentType == null
)
);

Assert.NotNull(
parameters.FirstOrDefault(
x => x.Type == ParameterType.GetOrPost &&
x.Name == "oauth_signature_method" &&
(string)x.Value == "PLAINTEXT" &&
x.ContentType == null
)
);

Assert.NotNull(
parameters.FirstOrDefault(
x => x.Type == ParameterType.GetOrPost && x.Name == "oauth_version" && (string)x.Value == "Version" && x.ContentType == null
)
);

Assert.NotNull(
parameters.FirstOrDefault(
x => x.Type == ParameterType.GetOrPost &&
x.Name == "oauth_nonce" &&
!string.IsNullOrWhiteSpace((string)x.Value) &&
x.ContentType == null
)
);

Assert.NotNull(
parameters.FirstOrDefault(
x => x.Type == ParameterType.GetOrPost &&
x.Name == "oauth_timestamp" &&
!string.IsNullOrWhiteSpace((string)x.Value) &&
x.ContentType == null
)
);
ParameterShouldBe("x_auth_username", "ClientUsername");
ParameterShouldBe("x_auth_password", "ClientPassword");
ParameterShouldBe("x_auth_mode", "client_auth");
ParameterShouldBe("oauth_consumer_key", "ConsumerKey");
ParameterShouldHaveValue("oauth_signature");
ParameterShouldBe("oauth_signature_method", "PLAINTEXT");
ParameterShouldBe("oauth_version", "Version");
ParameterShouldHaveValue("oauth_nonce");
ParameterShouldHaveValue("oauth_timestamp");

void ParameterShould(string name, Func<Parameter, bool> check) {
var parameter = parameters.FirstOrDefault(x => x.Type == ParameterType.GetOrPost && x.Name == name);
parameter.Should().NotBeNull();
check(parameter).Should().BeTrue();
}

void ParameterShouldBe(string name, string value) => ParameterShould(name, x => (string)x.Value == value);

void ParameterShouldHaveValue(string name) => ParameterShould(name, x => !string.IsNullOrWhiteSpace((string)x.Value));
}

[Theory]
Expand Down Expand Up @@ -200,4 +144,4 @@ public void Authenticate_ShouldAllowEmptyConsumerSecret_OnHttpAuthorizationHeade
Assert.Contains("OAuth", value!);
Assert.Contains($"oauth_signature=\"{OAuthTools.UrlEncodeStrict("&")}", value);
}
}
}