Skip to content

Commit

Permalink
fixes #175 - updated regex to find a signed package on `/plugin_packa…
Browse files Browse the repository at this point in the history
…ge` page (#176)

* fixes #175 - updated regex to find a signed package on `/plugin_package` page

* Add anchor tag fallback

---------

Co-authored-by: Bronley Plumb <[email protected]>
  • Loading branch information
7thsky and TwitchBronBron authored Oct 9, 2024
1 parent ee5ee20 commit 1479b7f
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
43 changes: 43 additions & 0 deletions src/RokuDeploy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1482,6 +1482,13 @@ describe('index', () => {
expect(pkgPath).to.equal('pkgs//P6953175d5df120c0069c53de12515b9a.pkg');
});

it('should return created pkg from SD card on success', async () => {
mockDoPostRequest(fakePluginPackageResponse);

let pkgPath = await rokuDeploy.signExistingPackage(options);
expect(pkgPath).to.equal('pkgs/sdcard0/Pae6cec1eab06a45ca1a7f5b69edd3a20.pkg');
});

it('should return our fallback error if neither error or package link was detected', async () => {
mockDoPostRequest();
await expectThrowsAsync(
Expand Down Expand Up @@ -3790,3 +3797,39 @@ function getFakeResponseBody(messages: string): string {
</body>
</html>`;
}

const fakePluginPackageResponse = `
<!--
(c) 2019-2023 Roku, Inc. All content herein is protected by U.S.
copyright and other applicable intellectual property laws and may not be
copied without the express permission of Roku, Inc., which reserves all
rights. Reuse of any of this content for any purpose without the
permission of Roku, Inc. is strictly prohibited.
-->
<html>
<head>
<meta charset="utf-8">
<meta name="HandheldFriendly" content="True">
<title> Roku Development Kit </title>
<link rel="stylesheet" type="text/css" media="screen" href="css/global.css" />
</head>
<body>
<div id="root" style="background: #fff">
</div>
<div style="display:none">
</div>
<div style="display:none">
<a href="pkgs//Pae6cec1eab06a45ca1a7f5b69edd3a20.pkg">Pae6cec1eab06a45ca1a7f5b69edd3a20.pkg</a></div>
<script type="text/javascript" src="css/global.js"></script>
<script type="text/javascript" src="js/common.js"></script>
<script type="text/javascript">
document.addEventListener("DOMContentLoaded", function (event) {
var params = JSON.parse('{"messages":null,"metadata":{"dev_id":"85ad433fddab9079e6cc378e736544c21e1f7123","dev_key":true,"voice_sdk":false},"packages":[{"appType":"channel","archiveFileName":"some-package.zip","fileType":"zip","id":"0","location":"sdcard","md5":"da4a98f08d45aea6e14a481ff481ffbe","pkgPath":"pkgs/sdcard0/Pae6cec1eab06a45ca1a7f5b69edd3a20.pkg","size":"455694"}]}');
var hasPackage = params.packages.length > 0;
</script>
</body>
</html>
`;
8 changes: 7 additions & 1 deletion src/RokuDeploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,13 @@ export class RokuDeploy {
throw new errors.FailedDeviceResponseError(failedSearchMatches[1], results);
}

let pkgSearchMatches = /<a href="(pkgs\/[^\.]+\.pkg)">/.exec(results.body);
//grab the package url from the JSON on the page if it exists (https://regex101.com/r/1HUXgk/1)
let pkgSearchMatches = /"pkgPath"\s*:\s*"(.*?)"/.exec(results.body);
if (pkgSearchMatches) {
return pkgSearchMatches[1];
}
//for some reason we couldn't find the pkgPath from json, look in the <a> tag
pkgSearchMatches = /<a href="(pkgs\/[^\.]+\.pkg)">/.exec(results.body);
if (pkgSearchMatches) {
return pkgSearchMatches[1];
}
Expand Down

0 comments on commit 1479b7f

Please sign in to comment.