-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: Token with sprite and glyphs (#192)
* export Util.formatStyle so we can run unit tests * add unit test to show token issue * fix sprite token issue * unit test to check if token added to glyphs * fix token added to glyphs (Fonts) * Update spec/UtilSpec.js Co-authored-by: Patrick Arlt <[email protected]> * Update spec/UtilSpec.js Co-authored-by: Patrick Arlt <[email protected]> * Update spec/UtilSpec.js Co-authored-by: Patrick Arlt <[email protected]> * Update spec/UtilSpec.js Co-authored-by: Patrick Arlt <[email protected]> * check for same domain between style URL and sprite/glyph URL * updated test names --------- Co-authored-by: Patrick Arlt <[email protected]>
- Loading branch information
1 parent
5e6aa8c
commit 30f8267
Showing
3 changed files
with
175 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
/* eslint-env mocha */ | ||
const metadata = { | ||
tiles: ['tile/{z}/{y}/{x}.pbf'], | ||
tileInfo: { | ||
lods: [ | ||
{ | ||
level: 0, | ||
resolution: 78271.516964, | ||
scale: 295828763.7957775 | ||
} | ||
] | ||
} | ||
}; | ||
|
||
describe('Util', function () { | ||
it('should include the token in the sprite URL when the sprite URL is relative', function () { | ||
const spriteUrl = '../sprites/sprite'; | ||
const token = 'asdf'; | ||
const styleUrl = | ||
'https://tiles.arcgis.com/tiles/test/arcgis/rest/services/test/VectorTileServer/resources/styles/root.json'; | ||
const fullSpriteUrl = | ||
'https://tiles.arcgis.com/tiles/test/arcgis/rest/services/test/VectorTileServer/resources/sprites/sprite'; | ||
|
||
const style = L.esri.Vector.Util.formatStyle( | ||
{ | ||
version: 8, | ||
sprite: spriteUrl, | ||
glyphs: '../fonts/{fontstack}/{range}.pbf', | ||
sources: { | ||
esri: { | ||
type: 'vector', | ||
attribution: 'test', | ||
bounds: [-180, -85.0511, 180, 85.0511], | ||
minzoom: 0, | ||
maxzoom: 19, | ||
scheme: 'xyz', | ||
url: '../../' | ||
} | ||
}, | ||
layers: [] | ||
}, | ||
styleUrl, | ||
metadata, | ||
token | ||
); | ||
|
||
// console.log("style.sprite", style.sprite); | ||
expect(style.sprite).to.equal(`${fullSpriteUrl}?token=${token}`); | ||
}); | ||
|
||
it('should include the token in the sprite URL when the sprite URL starts with https', function () { | ||
const spriteUrl = | ||
'https://www.arcgis.com/sharing/rest/content/items/123456789/resources/sprites/sprite-1679474043120'; | ||
const styleUrl = | ||
'https://www.arcgis.com/sharing/rest/content/items/asdf/resources/styles/root.json'; | ||
const token = 'asdf'; | ||
|
||
const style = L.esri.Vector.Util.formatStyle( | ||
{ | ||
version: 8, | ||
sprite: spriteUrl, | ||
glyphs: '../fonts/{fontstack}/{range}.pbf', | ||
sources: { | ||
esri: { | ||
type: 'vector', | ||
attribution: 'test', | ||
bounds: [-180, -85.0511, 180, 85.0511], | ||
minzoom: 0, | ||
maxzoom: 19, | ||
scheme: 'xyz', | ||
url: '../../' | ||
} | ||
}, | ||
layers: [] | ||
}, | ||
styleUrl, | ||
metadata, | ||
token | ||
); | ||
|
||
expect(style.sprite).to.equal(`${spriteUrl}?token=${token}`); | ||
}); | ||
|
||
it('should include the token in the glyph URL when the glyph URL is relative', function () { | ||
const token = 'asdf'; | ||
const glyphUrl = '../fonts/{fontstack}/{range}.pbf'; | ||
const styleUrl = | ||
'https://tiles.arcgis.com/tiles/test/arcgis/rest/services/test/VectorTileServer/resources/styles/root.json'; | ||
const fullGlyphUrl = | ||
'https://tiles.arcgis.com/tiles/test/arcgis/rest/services/test/VectorTileServer/resources/fonts/{fontstack}/{range}.pbf'; | ||
|
||
const style = L.esri.Vector.Util.formatStyle( | ||
{ | ||
version: 8, | ||
sprite: 'https://www.arcgis.com/sharing/rest/content/items/123456789/resources/sprites/sprite-1679474043120', | ||
glyphs: glyphUrl, | ||
sources: { | ||
esri: { | ||
type: 'vector', | ||
attribution: 'test', | ||
bounds: [-180, -85.0511, 180, 85.0511], | ||
minzoom: 0, | ||
maxzoom: 19, | ||
scheme: 'xyz', | ||
url: '../../' | ||
} | ||
}, | ||
layers: [] | ||
}, | ||
styleUrl, | ||
metadata, | ||
token | ||
); | ||
|
||
expect(style.glyphs).to.equal(`${fullGlyphUrl}?token=${token}`); | ||
}); | ||
|
||
it('should include the token in the glyph URL when the glyph URL starts with https', function () { | ||
const token = 'asdf'; | ||
const glyphUrl = 'https://www.arcgis.com/sharing/rest/content/items/123456789//resources/fonts/{fontstack}/{range}.pbf'; | ||
const styleUrl = | ||
'https://www.arcgis.com/sharing/rest/content/items/asdf/resources/styles/root.json'; | ||
|
||
const style = L.esri.Vector.Util.formatStyle( | ||
{ | ||
version: 8, | ||
sprite: 'https://www.arcgis.com/sharing/rest/content/items/123456789/resources/sprites/sprite-1679474043120', | ||
glyphs: glyphUrl, | ||
sources: { | ||
esri: { | ||
type: 'vector', | ||
attribution: 'test', | ||
bounds: [-180, -85.0511, 180, 85.0511], | ||
minzoom: 0, | ||
maxzoom: 19, | ||
scheme: 'xyz', | ||
url: '../../' | ||
} | ||
}, | ||
layers: [] | ||
}, | ||
styleUrl, | ||
metadata, | ||
token | ||
); | ||
|
||
expect(style.glyphs).to.equal(`${glyphUrl}?token=${token}`); | ||
}); | ||
}); |
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