ChannelCredentialsTest.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #region Copyright notice and license
  2. // Copyright 2015 gRPC authors.
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. #endregion
  16. using System;
  17. using Grpc.Core.Internal;
  18. using NUnit.Framework;
  19. namespace Grpc.Core.Tests
  20. {
  21. public class ChannelCredentialsTest
  22. {
  23. [Test]
  24. public void InsecureCredentials_IsNonComposable()
  25. {
  26. Assert.IsFalse(ChannelCredentials.Insecure.IsComposable);
  27. }
  28. [Test]
  29. public void ChannelCredentials_CreateComposite()
  30. {
  31. var composite = ChannelCredentials.Create(new FakeChannelCredentials(true), new FakeCallCredentials());
  32. Assert.IsFalse(composite.IsComposable);
  33. Assert.Throws(typeof(ArgumentNullException), () => ChannelCredentials.Create(null, new FakeCallCredentials()));
  34. Assert.Throws(typeof(ArgumentNullException), () => ChannelCredentials.Create(new FakeChannelCredentials(true), null));
  35. // forbid composing non-composable
  36. Assert.Throws(typeof(ArgumentException), () => ChannelCredentials.Create(new FakeChannelCredentials(false), new FakeCallCredentials()));
  37. }
  38. [Test]
  39. public void ChannelCredentials_NativeCredentialsAreReused()
  40. {
  41. // always returning the same native object is critical for subchannel sharing to work with secure channels
  42. var creds = new SslCredentials();
  43. var nativeCreds1 = creds.ToNativeCredentials();
  44. var nativeCreds2 = creds.ToNativeCredentials();
  45. Assert.AreSame(nativeCreds1, nativeCreds2);
  46. }
  47. }
  48. }