@@ -79,31 +79,44 @@ public void TryRewriteUri_FailsForRelativeUris()
7979 }
8080
8181 [ Theory ]
82- [ InlineData ( "http://bank" , "https://some.host:3499/v1.0/invoke/bank/method/" ) ]
83- [ InlineData ( "http://Bank" , "https://some.host:3499/v1.0/invoke/Bank/method/" ) ]
84- [ InlineData ( "http://bank:3939" , "https://some.host:3499/v1.0/invoke/bank/method/" ) ]
85- [ InlineData ( "http://Bank:3939" , "https://some.host:3499/v1.0/invoke/Bank/method/" ) ]
86- [ InlineData ( "http://app-id.with.dots" , "https://some.host:3499/v1.0/invoke/app-id.with.dots/method/" ) ]
87- [ InlineData ( "http://App-id.with.dots" , "https://some.host:3499/v1.0/invoke/App-id.with.dots/method/" ) ]
88- [ InlineData ( "http://bank:3939/" , "https://some.host:3499/v1.0/invoke/bank/method/" ) ]
89- [ InlineData ( "http://Bank:3939/" , "https://some.host:3499/v1.0/invoke/Bank/method/" ) ]
90- [ InlineData ( "http://bank:3939/some/path" , "https://some.host:3499/v1.0/invoke/bank/method/some/path" ) ]
91- [ InlineData ( "http://Bank:3939/some/path" , "https://some.host:3499/v1.0/invoke/Bank/method/some/path" ) ]
92- [ InlineData ( "http://bank:3939/some/path?q=test&p=another#fragment" , "https://some.host:3499/v1.0/invoke/bank/method/some/path?q=test&p=another#fragment" ) ]
93- [ InlineData ( "http://Bank:3939/some/path?q=test&p=another#fragment" , "https://some.host:3499/v1.0/invoke/Bank/method/some/path?q=test&p=another#fragment" ) ]
94- public void TryRewriteUri_RewritesUriToDaprInvoke ( string uri , string expected )
82+ [ InlineData ( null , "http://bank" , "https://some.host:3499/v1.0/invoke/bank/method/" ) ]
83+ [ InlineData ( "bank" , "http://bank" , "https://some.host:3499/v1.0/invoke/bank/method/" ) ]
84+ [ InlineData ( null , "http://Bank" , "https://some.host:3499/v1.0/invoke/Bank/method/" ) ]
85+ [ InlineData ( "Bank" , "http://Bank" , "https://some.host:3499/v1.0/invoke/Bank/method/" ) ]
86+ [ InlineData ( null , "http://bank:3939" , "https://some.host:3499/v1.0/invoke/bank/method/" ) ]
87+ [ InlineData ( "bank" , "http://bank:3939" , "https://some.host:3499/v1.0/invoke/bank/method/" ) ]
88+ [ InlineData ( null , "http://Bank:3939" , "https://some.host:3499/v1.0/invoke/Bank/method/" ) ]
89+ [ InlineData ( "Bank" , "http://Bank:3939" , "https://some.host:3499/v1.0/invoke/Bank/method/" ) ]
90+ [ InlineData ( null , "http://app-id.with.dots" , "https://some.host:3499/v1.0/invoke/app-id.with.dots/method/" ) ]
91+ [ InlineData ( "app-id.with.dots" , "http://app-id.with.dots" , "https://some.host:3499/v1.0/invoke/app-id.with.dots/method/" ) ]
92+ [ InlineData ( null , "http://App-id.with.dots" , "https://some.host:3499/v1.0/invoke/App-id.with.dots/method/" ) ]
93+ [ InlineData ( "App-id.with.dots" , "http://App-id.with.dots" , "https://some.host:3499/v1.0/invoke/App-id.with.dots/method/" ) ]
94+ [ InlineData ( null , "http://bank:3939/" , "https://some.host:3499/v1.0/invoke/bank/method/" ) ]
95+ [ InlineData ( "bank" , "http://bank:3939/" , "https://some.host:3499/v1.0/invoke/bank/method/" ) ]
96+ [ InlineData ( null , "http://Bank:3939/" , "https://some.host:3499/v1.0/invoke/Bank/method/" ) ]
97+ [ InlineData ( "Bank" , "http://Bank:3939/" , "https://some.host:3499/v1.0/invoke/Bank/method/" ) ]
98+ [ InlineData ( null , "http://bank:3939/some/path" , "https://some.host:3499/v1.0/invoke/bank/method/some/path" ) ]
99+ [ InlineData ( "bank" , "http://bank:3939/some/path" , "https://some.host:3499/v1.0/invoke/bank/method/some/path" ) ]
100+ [ InlineData ( null , "http://Bank:3939/some/path" , "https://some.host:3499/v1.0/invoke/Bank/method/some/path" ) ]
101+ [ InlineData ( "Bank" , "http://Bank:3939/some/path" , "https://some.host:3499/v1.0/invoke/Bank/method/some/path" ) ]
102+ [ InlineData ( null , "http://bank:3939/some/path?q=test&p=another#fragment" , "https://some.host:3499/v1.0/invoke/bank/method/some/path?q=test&p=another#fragment" ) ]
103+ [ InlineData ( "bank" , "http://bank:3939/some/path?q=test&p=another#fragment" , "https://some.host:3499/v1.0/invoke/bank/method/some/path?q=test&p=another#fragment" ) ]
104+ [ InlineData ( null , "http://Bank:3939/some/path?q=test&p=another#fragment" , "https://some.host:3499/v1.0/invoke/Bank/method/some/path?q=test&p=another#fragment" ) ]
105+ [ InlineData ( "Bank" , "http://Bank:3939/some/path?q=test&p=another#fragment" , "https://some.host:3499/v1.0/invoke/Bank/method/some/path?q=test&p=another#fragment" ) ]
106+ public void TryRewriteUri_WithNoAppId_RewritesUriToDaprInvoke ( string ? appId , string uri , string expected )
95107 {
96108 var handler = new InvocationHandler ( )
97109 {
98110 DaprEndpoint = "https://some.host:3499" ,
111+ AppId = appId ,
99112 } ;
100113
101114 Assert . True ( handler . TryRewriteUri ( new Uri ( uri ) , out var rewritten ) ) ;
102115 Assert . Equal ( expected , rewritten ! . OriginalString ) ;
103116 }
104117
105118 [ Fact ]
106- public async Task SendAsync_InvalidUri_ThrowsException ( )
119+ public async Task SendAsync_InvalidNotSetUri_ThrowsException ( )
107120 {
108121 var handler = new InvocationHandler ( ) ;
109122 var ex = await Assert . ThrowsAsync < ArgumentException > ( async ( ) =>
@@ -114,6 +127,19 @@ public async Task SendAsync_InvalidUri_ThrowsException()
114127 Assert . Contains ( "The request URI '' is not a valid Dapr service invocation destination." , ex . Message ) ;
115128 }
116129
130+ [ Fact ]
131+ public async Task SendAsync_InvalidUriWithAppId_ThrowsException ( )
132+ {
133+ var handler = new InvocationHandler ( ) { AppId = "bank" } ;
134+ string fakeUrl = "http://invalid/test" ;
135+ var ex = await Assert . ThrowsAsync < ArgumentException > ( async ( ) =>
136+ {
137+ await CallSendAsync ( handler , new HttpRequestMessage ( ) { RequestUri = new Uri ( fakeUrl ) } ) ; // No URI set
138+ } ) ;
139+
140+ Assert . Contains ( $ "The request URI '{ fakeUrl } ' is not a valid Dapr service invocation destination.", ex . Message ) ;
141+ }
142+
117143 [ Fact ]
118144 public async Task SendAsync_RewritesUri ( )
119145 {
@@ -138,6 +164,31 @@ public async Task SendAsync_RewritesUri()
138164 Assert . False ( request . Headers . TryGetValues ( "dapr-api-token" , out _ ) ) ;
139165 }
140166
167+ [ Fact ]
168+ public async Task SendAsync_RewritesUri_AndAppId ( )
169+ {
170+ var uri = "http://bank/accounts/17?" ;
171+
172+ var capture = new CaptureHandler ( ) ;
173+ var handler = new InvocationHandler ( )
174+ {
175+ InnerHandler = capture ,
176+
177+ DaprEndpoint = "https://localhost:5000" ,
178+ DaprApiToken = null ,
179+ AppId = "bank"
180+ } ;
181+
182+ var request = new HttpRequestMessage ( HttpMethod . Post , uri ) ;
183+ var response = await CallSendAsync ( handler , request ) ;
184+
185+ Assert . Equal ( "https://localhost:5000/v1.0/invoke/bank/method/accounts/17?" , capture . RequestUri ? . OriginalString ) ;
186+ Assert . Null ( capture . DaprApiToken ) ;
187+
188+ Assert . Equal ( uri , request . RequestUri ? . OriginalString ) ;
189+ Assert . False ( request . Headers . TryGetValues ( "dapr-api-token" , out _ ) ) ;
190+ }
191+
141192 [ Fact ]
142193 public async Task SendAsync_RewritesUri_AndAddsApiToken ( )
143194 {
0 commit comments