-
Notifications
You must be signed in to change notification settings - Fork 0
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
Routine maintenance 2023-07 #111
Changes from 10 commits
ba64b3c
3216c5f
316fa57
f1da174
90e22e8
7881f62
fb77dc0
c239e58
f00ac24
f3aea7e
dae4596
cd32693
c39395f
4c44dd3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env sh | ||
. "$(dirname -- "$0")/_/husky.sh" | ||
|
||
yarn run docs && git add docs.md |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
18 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
language: node_js | ||
node_js: | ||
- '8' | ||
dist: focal | ||
cache: yarn | ||
before_script: | ||
- 'yarn lint' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,16 +14,16 @@ test('getAuthenticationContext returns undefined when lp_auth cookie is set to a | |
}) | ||
|
||
test('getAuthenticationContext returns undefined when lp_auth cookie does not contain a token', () => { | ||
Cookies.set('lp_auth', {}) | ||
Cookies.set('lp_auth', JSON.stringify({})) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In v3, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good. Any value in creating a testing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I could be convinced if the source code was using it, but I'm pretty ok with being repetitive in tests! |
||
expect(getAuthenticationContext()).toEqual(undefined) | ||
}) | ||
|
||
test('getAuthenticationContext returns undefined when lp_auth cookie contains an invalid token', () => { | ||
Cookies.set('lp_auth', { token: false, context: CONTEXT }) | ||
Cookies.set('lp_auth', JSON.stringify({ token: false, context: CONTEXT })) | ||
expect(getAuthenticationContext()).toEqual(undefined) | ||
}) | ||
|
||
test('getAuthenticationContext returns the context string when lp_auth cookie contains a valid context', () => { | ||
Cookies.set('lp_auth', { token: true, context: CONTEXT }) | ||
Cookies.set('lp_auth', JSON.stringify({ token: true, context: CONTEXT })) | ||
expect(getAuthenticationContext()).toEqual(CONTEXT) | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,6 +50,19 @@ test('http adds custom CSRF token to request', () => { | |
}) | ||
}) | ||
|
||
test('http does not add attempt to CSRF token on the server', () => { | ||
const spyDocument = jest.spyOn(global, 'document', 'get') | ||
spyDocument.mockImplementation(() => undefined) | ||
Comment on lines
+54
to
+55
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This gets us test coverage for line 11 of |
||
|
||
return http(successUrl, { | ||
method: 'POST', | ||
csrf: CUSTOM_TAG_NAME | ||
}).then((res) => { | ||
expect(res.headers.xCSRFToken).toEqual(undefined) | ||
spyDocument.mockRestore() | ||
}) | ||
}) | ||
|
||
test('http passes url to request', () => { | ||
return http(successUrl).then((res) => { | ||
expect(res.url).toEqual(successUrl) | ||
|
@@ -62,6 +75,12 @@ test('http can accept a single object argument', () => { | |
}) | ||
}) | ||
|
||
test('http throws an error if `url` is not provided', async () => { | ||
await expect(http()).rejects.toThrow() | ||
await expect(http("", {})).rejects.toThrow() | ||
await expect(http({ url : null })).rejects.toThrow() | ||
chawes13 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}) | ||
|
||
test('http prepends custom root to request', () => { | ||
const root = 'http://root/api/v1' | ||
return http(successUrl, { | ||
|
@@ -286,6 +305,16 @@ test('http sets basic auth header if `auth` is present', () => { | |
}) | ||
}) | ||
|
||
// Note: this isn't recommended and is super insecure, but technically the HTTP spec does allow it | ||
test('http sets basic auth, even if username and password are not provided', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a test for behavior that already exists. It gives us test coverage for the right-hand expression of |
||
return http(successUrl, { | ||
method: 'POST', | ||
auth: {}, | ||
}).then(res => { | ||
expect(res.headers.authorization).toEqual(`Basic ${Base64.btoa(':')}`) | ||
}) | ||
}) | ||
|
||
test('http returns null when content-length is zero', () => { | ||
return http(successUrl, { headers: { 'Content-Length': '0' }}) | ||
.then((res) => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is weird, I need to look into it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Later version(s?) of
documentation
expect an explanation for the return value. We were defining that in the description of both of these, instead of here.