Repository: snowflakedb/gosnowflake
Pull request #1238 (2024-11-05 09:26:20)

SNOW-1569290 Make Azure headers case insensitive
### Description

SNOW-1569290 Azure client treated headers as case sensitive before, which causes fails when downloading files uploaded by other drivers.

### Checklist
- [x] Created tests which fail without the change (if possible)
- [x] Extended the README / documentation, if necessary


codecov[bot]: ## [Codecov](https://app.codecov.io/gh/snowflakedb/gosnowflake/pull/1238?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=snowflakedb) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 82.58%. Comparing base [(`27e76c9`)](https://app.codecov.io/gh/snowflakedb/gosnowflake/commit/27e76c9349a38895e20a847b4c08d01d39ec4d03?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=snowflakedb) to head [(`a6bf5f7`)](https://app.codecov.io/gh/snowflakedb/gosnowflake/commit/a6bf5f7e1090bc400fb25290ba205c4d5c877c8c?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=snowflakedb).
> Report is 1 commits behind head on master.

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##           master    #1238      +/-   ##
==========================================
- Coverage   82.59%   82.58%   -0.01%     
==========================================
  Files          55       55              
  Lines       13315    13321       +6     
==========================================
+ Hits        10997    11001       +4     
- Misses       2318     2320       +2     
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/snowflakedb/gosnowflake/pull/1238?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=snowflakedb).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=snowflakedb).


Patch:
diff --git a/azure_storage_client.go b/azure_storage_client.go
index bca868c..ae1b721 100644
--- a/azure_storage_client.go
+++ b/azure_storage_client.go
@@ -105,17 +105,17 @@ func (util *snowflakeAzureClient) getFileHeader(meta *fileMetadata, filename str
 	}
 
 	meta.resStatus = uploaded
-	metadata := resp.Metadata
+	metadata := withLowerKeys(resp.Metadata)
 	var encData encryptionData
 
-	_, ok = metadata["Encryptiondata"]
+	_, ok = metadata["encryptiondata"]
 	if ok {
-		if err = json.Unmarshal([]byte(*metadata["Encryptiondata"]), &encData); err != nil {
+		if err = json.Unmarshal([]byte(*metadata["encryptiondata"]), &encData); err != nil {
 			return nil, err
 		}
 	}
 
-	matdesc, ok := metadata["Matdesc"]
+	matdesc, ok := metadata["matdesc"]
 	if !ok {
 		// matdesc is not in response, use empty string
 		matdesc = new(string)
@@ -126,7 +126,7 @@ func (util *snowflakeAzureClient) getFileHeader(meta *fileMetadata, filename str
 		*matdesc,
 	}
 
-	digest, ok := metadata["Sfcdigest"]
+	digest, ok := metadata["sfcdigest"]
 	if !ok {
 		// sfcdigest is not in response, use empty string
 		digest = new(string)
diff --git a/util.go b/util.go
index 53fef8e..b18238b 100644
--- a/util.go
+++ b/util.go
@@ -331,3 +331,11 @@ func contains[T comparable](s []T, e T) bool {
 func chooseRandomFromRange(min float64, max float64) float64 {
 	return rand.Float64()*(max-min) + min
 }
+
+func withLowerKeys[T any](in map[string]T) map[string]T {
+	out := make(map[string]T)
+	for k, v := range in {
+		out[strings.ToLower(k)] = v
+	}
+	return out
+}


Test patch:
diff --git a/util_test.go b/util_test.go
index ae6c1af..9a41cd4 100644
--- a/util_test.go
+++ b/util_test.go
@@ -400,3 +400,12 @@ func randomString(n int) string {
 	}
 	return string(b)
 }
+
+func TestWithLowerKeys(t *testing.T) {
+	m := make(map[string]string)
+	m["abc"] = "def"
+	m["GHI"] = "KLM"
+	lowerM := withLowerKeys(m)
+	assertEqualE(t, lowerM["abc"], "def")
+	assertEqualE(t, lowerM["ghi"], "KLM")
+}