Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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