27
27
using Microsoft . Azure . Commands . Common . Authentication . Models ;
28
28
using Microsoft . Azure . Commands . Profile ;
29
29
using Microsoft . Azure . Commands . Profile . Models ;
30
+ using Microsoft . Azure . Subscriptions . Models ;
31
+ using Hyak . Common ;
30
32
31
33
namespace Microsoft . Azure . Commands . ResourceManager . Common . Test
32
34
{
@@ -67,6 +69,41 @@ private static RMProfileClient SetupTestEnvironment(List<string> tenants, params
67
69
return new RMProfileClient ( profile ) ;
68
70
}
69
71
72
+ [ Fact ]
73
+ [ Trait ( Category . AcceptanceType , Category . CheckIn ) ]
74
+ public void SubscriptionIdNotInFirstTenant ( )
75
+ {
76
+ var tenants = new List < string > { DefaultTenant . ToString ( ) , Guid . NewGuid ( ) . ToString ( ) } ;
77
+ var subscriptionInSecondTenant = Guid . NewGuid ( ) . ToString ( ) ;
78
+ var firstList = new List < string > { DefaultSubscription . ToString ( ) } ;
79
+ var secondList = new List < string > { Guid . NewGuid ( ) . ToString ( ) , subscriptionInSecondTenant } ;
80
+ var client = SetupTestEnvironment ( tenants , firstList , secondList ) ;
81
+
82
+ ( ( MockTokenAuthenticationFactory ) AzureSession . AuthenticationFactory ) . TokenProvider = ( account , environment , tenant ) =>
83
+ new MockAccessToken
84
+ {
85
+
86
+ LoginType = LoginType . OrgId ,
87
+ AccessToken = "bbb" ,
88
+ TenantId = DefaultTenant . ToString ( )
89
+ } ;
90
+
91
+ var getAsyncResponses = new Queue < Func < GetSubscriptionResult > > ( ) ;
92
+ getAsyncResponses . Enqueue ( ( ) =>
93
+ {
94
+ throw new CloudException ( "InvalidAuthenticationTokenTenant: The access token is from the wrong issuer" ) ;
95
+ } ) ;
96
+ MockSubscriptionClientFactory . SetGetAsyncResponses ( getAsyncResponses ) ;
97
+
98
+ var azureRmProfile = client . Login (
99
+ Context . Account ,
100
+ Context . Environment ,
101
+ null ,
102
+ subscriptionInSecondTenant ,
103
+ null ,
104
+ null ) ;
105
+ }
106
+
70
107
[ Fact ]
71
108
[ Trait ( Category . AcceptanceType , Category . CheckIn ) ]
72
109
public void TokenIdAndAccountIdMismatch ( )
@@ -78,7 +115,6 @@ public void TokenIdAndAccountIdMismatch()
78
115
var thirdList = new List < string > { DefaultSubscription . ToString ( ) , secondsubscriptionInTheFirstTenant } ;
79
116
var fourthList = new List < string > { DefaultSubscription . ToString ( ) , secondsubscriptionInTheFirstTenant } ;
80
117
var client = SetupTestEnvironment ( tenants , firstList , secondList , thirdList , fourthList ) ;
81
-
82
118
var tokens = new Queue < MockAccessToken > ( ) ;
83
119
tokens . Enqueue ( new MockAccessToken
84
120
{
0 commit comments