0

I am using azure-cli to generate SAS token

az storage blob generate-sas --account-key mykey --account-name myaccount --container-name my --expiry 2023-01-01T00:00:00Z --name 0.0.1/uk/787867898767/structure/calendar/a12calendar.json --permissions r

Which returns a SAS token which looks like:

se=2023-01-01T00%3A00%3A00Z&sp=r&sv=2020-02-10&sr=b&sig=u2VWd2i8cdYhkjA%2BZRBCYZbHwmZDCrjirs%2BYstwxmjI%3D

I have a rest assured test which does a GET to

given().get("https://myaccount.blob.core.windows.net/mycontainer/0.0.1/uk/787867898767/structure/calendar/a12calendar.json?se=2023-01-01T00%3A00%3A00Z&sp=r&sv=2020-02-10&sr=b&sig=u2VWd2i8cdYhkjA%2BZRBCYZbHwmZDCrjirs%2BYstwxmjI%3DD").then().statusCode(200)

which fails with a HTTP 403.

    <?xml version="1.0" encoding="utf-8"?><Error><Code>AuthenticationFailed</Code><Message>Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
RequestId:5ab15b27-701e-00b3-298c-b0ffa0000000
Time:2021-09-23T15:08:56.1619254Z</Message><AuthenticationErrorDetail>Signature fields not well formed.</AuthenticationErrorDetail></Error>

BUT the same url works fine on Postman and Chrome. Looks like some kind of encoding issue, but can't find what. Any help would be hugely appreciated .

Boon
  • 401
  • 1
  • 6
  • 17
  • I am guessing that something is going on with encoding of your SAS token. Can you try by decoding the sas token and using that in your test. Your SAS token after decoding should look something like `se=2023-01-01T00:00:00Z&sp=r&sv=2020-02-10&sr=b&sig=u2VWd2i8cdYhkjA+ZRBCYZbHwmZDCrjirs+YstwxmjI=`. – Gaurav Mantri Sep 23 '21 at 15:17
  • @GauravMantri - yes you are right. I have shared the answer below. Please check. – Boon Sep 28 '21 at 09:23

1 Answers1

0

Ok the issue was with default RestAssured settings.

RestAssured has urlEncodingEnabled = true by default.

Set it to false using

RestAssured.urlEncodingEnabled = false;

if you face issue with url encoding.

Boon
  • 401
  • 1
  • 6
  • 17