-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adjust encoding of Azure block IDs (#68957)
Today we represent block IDs sent to Azure using the URL-safe base-64 encoding. This makes sense: these IDs appear in URLs. It turns out that Azure rejects this encoding for block IDs and instead demands that they are represented using the regular, URL-unsafe, base-64 encoding instead, then further wrapped in %-encoding to deal with the URL-unsafe characters that inevitably result. Relates #66489
- Loading branch information
1 parent
947f1eb
commit b3d5d32
Showing
5 changed files
with
43 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
test/framework/src/main/java/org/elasticsearch/repositories/azure/AzureFixtureHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.repositories.azure; | ||
|
||
import org.elasticsearch.common.Strings; | ||
|
||
import java.util.Base64; | ||
|
||
public class AzureFixtureHelper { | ||
private AzureFixtureHelper() { | ||
} | ||
|
||
public static boolean assertValidBlockId(String blockId) { | ||
assert Strings.hasText(blockId) : "blockId missing"; | ||
try { | ||
final byte[] decode = Base64.getDecoder().decode(blockId); | ||
// all block IDs for a blob must be the same length and <64 bytes prior to decoding. | ||
// Elasticsearch generates them all to be 15 bytes long so we can just assert that: | ||
assert decode.length == 15 : "blockid [" + blockId + "] decodes to [" + decode.length + "] bytes"; | ||
} catch (Exception e) { | ||
assert false : new AssertionError("blockid [" + blockId + "] is not in base64", e); | ||
} | ||
return true; | ||
} | ||
} |