@@ -475,7 +475,7 @@ public void testGetCommonResponseClientException() throws ClientException, IOExc
475
475
Mockito .when (response .isSuccess ()).thenReturn (false );
476
476
Mockito .when (response .getHttpContentType ()).thenReturn (FormatType .XML );
477
477
Mockito .when (response .getHttpContentString ()).thenReturn (makeAcsErrorXML ("" , "" , "500" , "ServerException" , "" ));
478
- Mockito .when (response .getStatus ()).thenReturn (401 );
478
+ Mockito .when (response .getStatus ()).thenReturn (404 );
479
479
thrown .expect (ClientException .class );
480
480
spyClient .getCommonResponse (commonRequest );
481
481
}
@@ -516,7 +516,7 @@ public void testResponseNotIncompleteSignatureError() throws ClientException {
516
516
DefaultAcsClient client = new DefaultAcsClient (profile );
517
517
DefaultAcsClient spyClient = Mockito .spy (client );
518
518
HttpResponse response = Mockito .mock (HttpResponse .class );
519
- Mockito .when (response .getStatus ()).thenReturn (401 );
519
+ Mockito .when (response .getStatus ()).thenReturn (400 );
520
520
Mockito .when (response .getHttpContentType ()).thenReturn (FormatType .XML );
521
521
Mockito .when (response .getHttpContentString ()).thenReturn (makeAcsErrorXML ("" , "" , "Not IncompleteSignature" ,
522
522
"ClientException" , "" ));
@@ -537,7 +537,7 @@ public void testResponseInvalidAccessKeySecretError() throws ClientException {
537
537
DefaultAcsClient client = new DefaultAcsClient (profile );
538
538
DefaultAcsClient spyClient = Mockito .spy (client );
539
539
HttpResponse response = Mockito .mock (HttpResponse .class );
540
- Mockito .when (response .getStatus ()).thenReturn (401 );
540
+ Mockito .when (response .getStatus ()).thenReturn (400 );
541
541
Mockito .when (response .getHttpContentType ()).thenReturn (FormatType .XML );
542
542
AcsRequest request = Mockito .mock (AcsRequest .class );
543
543
request .strToSign = "GET&%2F%3DDescriat%3DXML%26" ;
@@ -560,7 +560,7 @@ public void testResponseSignatureNullError() throws ClientException {
560
560
DefaultAcsClient client = new DefaultAcsClient (profile );
561
561
DefaultAcsClient spyClient = Mockito .spy (client );
562
562
HttpResponse response = Mockito .mock (HttpResponse .class );
563
- Mockito .when (response .getStatus ()).thenReturn (401 );
563
+ Mockito .when (response .getStatus ()).thenReturn (400 );
564
564
Mockito .when (response .getHttpContentType ()).thenReturn (FormatType .XML );
565
565
AcsRequest request = Mockito .mock (AcsRequest .class );
566
566
request .strToSign = "GET&%2F&scribeInstancesDXML%26" ;
@@ -583,7 +583,7 @@ public void testResponseSignatureError() throws ClientException {
583
583
DefaultAcsClient client = new DefaultAcsClient (profile );
584
584
HttpResponse response = Mockito .mock (HttpResponse .class );
585
585
DefaultAcsClient spyClient = Mockito .spy (client );
586
- Mockito .when (response .getStatus ()).thenReturn (401 );
586
+ Mockito .when (response .getStatus ()).thenReturn (400 );
587
587
Mockito .when (response .getHttpContentType ()).thenReturn (FormatType .XML );
588
588
AcsRequest request = Mockito .mock (AcsRequest .class );
589
589
request .strToSign = "GET&%2F&Action%3DDescribeInances%26Format%3DXML%26" ;
@@ -596,6 +596,28 @@ public void testResponseSignatureError() throws ClientException {
596
596
spyClient .getAcsResponse (request );
597
597
}
598
598
599
+ @ Test
600
+ public void testResponseSignatureDoesNotMatch () throws ClientException {
601
+ Credential credential = Mockito .mock (Credential .class );
602
+ Mockito .when (credential .getSecurityToken ()).thenReturn (null );
603
+ DefaultProfile profile = Mockito .mock (DefaultProfile .class );
604
+ Mockito .when (profile .getCredential ()).thenReturn (credential );
605
+ DefaultAcsClient client = new DefaultAcsClient (profile );
606
+ HttpResponse response = Mockito .mock (HttpResponse .class );
607
+ DefaultAcsClient spyClient = Mockito .spy (client );
608
+ Mockito .when (response .getStatus ()).thenReturn (400 );
609
+ Mockito .when (response .getHttpContentType ()).thenReturn (FormatType .XML );
610
+ AcsRequest request = Mockito .mock (AcsRequest .class );
611
+ request .strToSign = "GET&%2F&Action%3DDescribeInances%26Format%3DXML%26" ;
612
+ String errorMessage = "signature does not conform to standards. server string to sign is:Error Signature" ;
613
+ Mockito .when (response .getHttpContentString ()).thenReturn (makeAcsErrorXML ("" , "" , "SignatureDoesNotMatch" ,
614
+ errorMessage , "" ));
615
+ Mockito .doReturn (response ).when (spyClient ).doAction (request );
616
+ thrown .expect (ClientException .class );
617
+ thrown .expectMessage ("SignatureDoesNotMatch : " + errorMessage );
618
+ spyClient .getAcsResponse (request );
619
+ }
620
+
599
621
@ SuppressWarnings ({ "unchecked" , "rawtypes" , "deprecation" })
600
622
@ Test
601
623
public void testResponseStringContentNull () throws ClientException {
@@ -606,7 +628,7 @@ public void testResponseStringContentNull() throws ClientException {
606
628
DefaultAcsClient client = new DefaultAcsClient (profile );
607
629
HttpResponse response = Mockito .mock (HttpResponse .class );
608
630
DefaultAcsClient spyClient = Mockito .spy (client );
609
- Mockito .when (response .getStatus ()).thenReturn (401 );
631
+ Mockito .when (response .getStatus ()).thenReturn (400 );
610
632
Mockito .when (response .getHttpContentType ()).thenReturn (FormatType .XML );
611
633
AcsRequest request = Mockito .mock (AcsRequest .class );
612
634
request .strToSign = "GET&%2F&ssddddfgfK" ;
0 commit comments