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

Add cookie auth and custom header feature #814

Merged
merged 1 commit into from
Oct 1, 2021
Merged

Add cookie auth and custom header feature #814

merged 1 commit into from
Oct 1, 2021

Conversation

Brent1LT
Copy link
Contributor

Checklist

General Contributing

  • Have you read the Code of Conduct and signed the CLA?

Is This a Code Change?

  • Non-code related change (markdown/git settings etc)
  • SDK Code Change
  • Example/Test Code Change

Validation

  • Does npm test pass?
  • Does npm run build pass?
  • Does npm run lint pass?

@codecov
Copy link

codecov bot commented Sep 29, 2021

Codecov Report

Merging #814 (5733e27) into main (b851e70) will increase coverage by 0.31%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #814      +/-   ##
==========================================
+ Coverage   65.20%   65.51%   +0.31%     
==========================================
  Files           7        7              
  Lines         773      780       +7     
==========================================
+ Hits          504      511       +7     
  Misses        269      269              
Flag Coverage Δ
integration 53.58% <42.85%> (-0.10%) ⬇️
unit 63.97% <100.00%> (+0.32%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/constants.js 100.00% <100.00%> (ø)
src/dropbox.js 96.10% <100.00%> (+0.32%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b851e70...5733e27. Read the comment docs.

chai.assert.equal(COOKIE, dbx.rpcRequest.getCall(0).args[2]);
});

it('errors if cookie auth is supplied an OAuth token', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is actually the behavior we want for cookie auth but can remove if not.

src/dropbox.js Outdated
@@ -206,5 +215,10 @@ export default class Dropbox {
if (this.pathRoot) {
options.headers['Dropbox-API-Path-Root'] = this.pathRoot;
}
if (this.customHeaders) {
for (const header in this.customHeaders) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

linter is failing from this line but I think this is actually the behavior we more or less want, can alter the code to satisfy linter but I feel like it just adds extra code for no reason. Can also ignore lint this line if we want

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Valid linter, we don't want to do this

src/dropbox.js Outdated
@@ -50,6 +51,8 @@ const b64 = typeof btoa === 'undefined'
* should only be used for testing as scaffolding to avoid making network requests.
* @arg {String} [options.domainDelimiter] - A custom delimiter to use when separating domain from
* subdomain. This should only be used for testing as scaffolding.
* @arg {Object} [options.customHeaders] - An object designed to set custom headers to use
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should have some indication of what format this object should be in

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also needs to be reflected in the TS types file or TS clients won't be able to use this

src/dropbox.js Outdated
@@ -125,6 +129,11 @@ export default class Dropbox {
break;
case NO_AUTH:
break;
case COOKIE:
if (this.auth.accessToken) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine, just break. We don't need to explicitely check this

src/dropbox.js Outdated
@@ -206,5 +215,10 @@ export default class Dropbox {
if (this.pathRoot) {
options.headers['Dropbox-API-Path-Root'] = this.pathRoot;
}
if (this.customHeaders) {
for (const header in this.customHeaders) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Valid linter, we don't want to do this

src/dropbox.js Outdated
@@ -50,6 +51,8 @@ const b64 = typeof btoa === 'undefined'
* should only be used for testing as scaffolding to avoid making network requests.
* @arg {String} [options.domainDelimiter] - A custom delimiter to use when separating domain from
* subdomain. This should only be used for testing as scaffolding.
* @arg {Object} [options.customHeaders] - An object designed to set custom headers to use
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also needs to be reflected in the TS types file or TS clients won't be able to use this

src/dropbox.js Outdated
if (this.customHeaders) {
const headerKeys = Object.keys(this.customHeaders);
headerKeys.forEach((header) => {
if (this.customHeaders[header]) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to check if it exists? Don't we know it exists if we just got the keys for the headers?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I thought the linter wanted an 'if' statement but I just realized if I do it this way then the linter doesn't care.

@@ -177,6 +181,8 @@ export interface DropboxOptions {
domain?: string;
// A custom delimiter to use when separating domain subdomain. This should only be used for testing as scaffolding.
domainDelimiter?: string;
// An object (in the form property: string) designed to set custom headers to use during a request.
customHeaders?: customHeaders;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can just use object, we don't need a custom type for this

@@ -177,6 +181,8 @@ export interface DropboxOptions {
domain?: string;
// A custom delimiter to use when separating domain subdomain. This should only be used for testing as scaffolding.
domainDelimiter?: string;
// An object (in the form property: string) designed to set custom headers to use during a request.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be more concise by saying something like an object of headers to their values

@@ -177,6 +181,8 @@ export interface DropboxOptions {
domain?: string;
// A custom delimiter to use when separating domain subdomain. This should only be used for testing as scaffolding.
domainDelimiter?: string;
// An object (in the form property: string) designed to set custom headers to use during a request.
customHeaders?: customHeaders;
}

export class DropboxResponseError<T> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is the template, you need to re-generate the sdk to get this into the generated code. Make sure your submodules are at the same place as main is (just pull from main in each repo)

@Brent1LT Brent1LT merged commit 7e2772b into main Oct 1, 2021
@Brent1LT Brent1LT deleted the cookie_auth branch October 1, 2021 17:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants