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

fix: do not remove trailing | from cache values #142

Merged
merged 1 commit into from
Aug 7, 2020
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
11 changes: 1 addition & 10 deletions src/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,6 @@ export async function get(
singleFileName,
] = result.split("|");

/* istanbul ignore if - this is to debug an exception we see in production */
if (!options.permissions && typeof permissionsString === "undefined") {
throw new Error(
`[@octokit/auth-app] Invalid cache. Key: ${cacheKey}. Result: ${result}`
);
}

const permissions =
options.permissions ||
permissionsString.split(/,/).reduce((permissions: Permissions, string) => {
Expand Down Expand Up @@ -91,9 +84,7 @@ export async function set(
data.repositorySelection,
permissionsString,
data.singleFileName,
]
.join("|")
.replace(/\|+$/, "");
].join("|");

await cache.set(key, value);
}
Expand Down
14 changes: 7 additions & 7 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1004,15 +1004,15 @@ test("supports custom cache", async () => {
expect(get).toBeCalledWith("123");
expect(set).toBeCalledWith(
"123",
"secret123|1970-01-01T00:00:00.000Z|1970-01-01T01:00:00.000Z|all|metadata"
"secret123|1970-01-01T00:00:00.000Z|1970-01-01T01:00:00.000Z|all|metadata|"
);
expect(CACHE).toStrictEqual({
"123":
"secret123|1970-01-01T00:00:00.000Z|1970-01-01T01:00:00.000Z|all|metadata",
"secret123|1970-01-01T00:00:00.000Z|1970-01-01T01:00:00.000Z|all|metadata|",
"123|content":
"secret123|1970-01-01T00:00:00.000Z|1970-01-01T01:00:00.000Z|all",
"secret123|1970-01-01T00:00:00.000Z|1970-01-01T01:00:00.000Z|all||",
"456":
"secret456|1970-01-01T00:00:00.000Z|1970-01-01T01:00:00.000Z|all|metadata",
"secret456|1970-01-01T00:00:00.000Z|1970-01-01T01:00:00.000Z|all|metadata|",
});
});

Expand Down Expand Up @@ -1066,7 +1066,7 @@ test("supports custom cache with async get/set", async () => {
expect(get).toBeCalledWith("123");
expect(set).toBeCalledWith(
"123",
"secret123|1970-01-01T00:00:00.000Z|1970-01-01T01:00:00.000Z|all|metadata"
"secret123|1970-01-01T00:00:00.000Z|1970-01-01T01:00:00.000Z|all|metadata|"
);
});

Expand Down Expand Up @@ -1476,8 +1476,8 @@ test("auth.hook() and custom cache", async () => {
expect(mock.done()).toBe(true);
expect(CACHE).toStrictEqual({
"123":
"secret123|1970-01-01T00:00:00.000Z|1970-01-01T01:00:00.000Z|all|metadata",
"secret123|1970-01-01T00:00:00.000Z|1970-01-01T01:00:00.000Z|all|metadata|",
"456":
"secret456|1970-01-01T00:00:00.000Z|1970-01-01T01:00:00.000Z|all|metadata",
"secret456|1970-01-01T00:00:00.000Z|1970-01-01T01:00:00.000Z|all|metadata|",
});
});