+144
-72
lines changedFilter options
+144
-72
lines changed Original file line number Diff line number Diff line change
@@ -282,29 +282,46 @@ describe('push', () => {
282
282
let fillCalled = false
283
283
let approvedCalled = false
284
284
let rejectedCalled = false
285
+
let onAuthArgs = null
286
+
let onAuthSuccessArgs = null
287
+
let onAuthFailureArgs = null
285
288
await push({
286
289
fs,
287
290
http,
288
291
gitdir,
289
292
remote: 'auth',
290
293
ref: 'master',
291
-
async onAuth({ url }) {
294
+
async onAuth(...args) {
292
295
fillCalled = true
296
+
onAuthArgs = args
293
297
return {
294
298
username: 'testuser',
295
299
password: 'testpassword',
296
300
}
297
301
},
298
-
async onAuthSuccess(auth) {
302
+
async onAuthSuccess(...args) {
299
303
approvedCalled = true
304
+
onAuthSuccessArgs = args
300
305
},
301
-
async onAuthFailure(auth) {
306
+
async onAuthFailure(...args) {
302
307
rejectedCalled = true
308
+
onAuthFailureArgs = args
303
309
},
304
310
})
305
311
expect(fillCalled).toBe(true)
306
312
expect(approvedCalled).toBe(true)
307
313
expect(rejectedCalled).toBe(false)
314
+
expect(onAuthArgs).toEqual([
315
+
`http://${localhost}:8888/test-push-server-auth.git`,
316
+
])
317
+
expect(onAuthSuccessArgs).toEqual([
318
+
`http://${localhost}:8888/test-push-server-auth.git`,
319
+
{
320
+
username: 'testuser',
321
+
password: 'testpassword',
322
+
},
323
+
])
324
+
expect(onAuthFailureArgs).toBeNull()
308
325
})
309
326
it('onAuthFailure', async () => {
310
327
// Setup
@@ -320,25 +337,32 @@ describe('push', () => {
320
337
let approvedCalled = false
321
338
let rejectedCalled = false
322
339
let err
340
+
let onAuthArgs = null
341
+
let onAuthSuccessArgs = null
342
+
let onAuthFailureArgs = null
343
+
323
344
try {
324
345
await push({
325
346
fs,
326
347
http,
327
348
gitdir,
328
349
remote: 'auth',
329
350
ref: 'master',
330
-
async onAuth({ url }) {
351
+
async onAuth(...args) {
331
352
fillCalled = true
353
+
onAuthArgs = args
332
354
return {
333
355
username: 'testuser',
334
356
password: 'NoT_rIgHt',
335
357
}
336
358
},
337
-
async onAuthSuccess(auth) {
359
+
async onAuthSuccess(...args) {
338
360
approvedCalled = true
361
+
onAuthSuccessArgs = args
339
362
},
340
-
async onAuthFailure(auth) {
363
+
async onAuthFailure(...args) {
341
364
rejectedCalled = true
365
+
onAuthFailureArgs = args
342
366
},
343
367
})
344
368
} catch (e) {
@@ -349,5 +373,16 @@ describe('push', () => {
349
373
expect(fillCalled).toBe(true)
350
374
expect(approvedCalled).toBe(false)
351
375
expect(rejectedCalled).toBe(true)
376
+
expect(onAuthArgs).toEqual([
377
+
`http://${localhost}:8888/test-push-server-auth.git`,
378
+
])
379
+
expect(onAuthSuccessArgs).toBeNull()
380
+
expect(onAuthFailureArgs).toEqual([
381
+
`http://${localhost}:8888/test-push-server-auth.git`,
382
+
{
383
+
username: 'testuser',
384
+
password: 'NoT_rIgHt',
385
+
},
386
+
])
352
387
})
353
388
})
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
1
1
{
2
-
"include": ["dist/index.js"],
2
+
"include": ["dist/index.js", "dist/http.js"],
3
3
"exclude": ["node_modules"],
4
4
"compilerOptions": {
5
5
"strictNullChecks": true,
Original file line number Diff line number Diff line change
@@ -13,14 +13,19 @@ Git does all its authentication using HTTPS Basic Authentication.
13
13
An `onAuth` function is called with a `url` and should return a credential object:
14
14
15
15
```ts
16
-
type AuthCallback = (url: string) => Promise<GitAuth>;
17
-
18
-
type GitAuth = {
19
-
username?: string;
20
-
password?: string;
21
-
token?: string;
22
-
oauth2format?: string;
23
-
}
16
+
/**
17
+
* @callback AuthCallback
18
+
* @param {string} url
19
+
* @returns {GitAuth | Promise<GitAuth>}
20
+
*/
21
+
22
+
/**
23
+
* @typedef {Object} GitAuth
24
+
* @property {string} [username]
25
+
* @property {string} [password]
26
+
* @property {string} [token]
27
+
* @property {string} [oauth2format]
28
+
*/
24
29
```
25
30
26
31
## Option 1: Username & Password
Original file line number Diff line number Diff line change
@@ -5,16 +5,14 @@ sidebar_label: onAuthFailure
5
5
6
6
The `onAuthFailure` callback is called when credentials fail. This is helpful to know if say, you have saved password and want to offer to delete ones that fail.
7
7
8
-
An `onAuthFailure` function is called with a `{ url, auth }` object.
8
+
An `onAuthFailure` function is called with a `url` and an `auth` object.
9
9
10
10
```js
11
11
/**
12
12
* @callback AuthFailureCallback
13
-
* @param {object} args.
14
-
* @param {string} args.url
15
-
* @param {GitAuth} args.auth
16
-
*
17
-
* @returns {Promise<void>}
13
+
* @param {string} url
14
+
* @param {GitAuth} auth
15
+
* @returns {void | Promise<void>}
18
16
*/
19
17
20
18
/**
@@ -32,7 +30,7 @@ An `onAuthFailure` function is called with a `{ url, auth }` object.
32
30
const git = require('isomorphic-git')
33
31
git.clone({
34
32
...,
35
-
onAuthFailure: ({ url, auth }) => {
33
+
onAuthFailure: (url, auth) => {
36
34
if (confirm('Access was denied. Delete saved password?')) {
37
35
forgetSavedPassword(url)
38
36
}
Original file line number Diff line number Diff line change
@@ -5,16 +5,14 @@ sidebar_label: onAuthSuccess
5
5
6
6
The `onAuthSuccess` callback is called when credentials fail. This is helpful to know if say, you want to offer to save a password but only after it succeeds.
7
7
8
-
An `onAuthSuccess` function is called with a `{ url, auth }` object.
8
+
An `onAuthSuccess` function is called with a `url` and an `auth` object.
9
9
10
10
```js
11
11
/**
12
12
* @callback AuthSuccessCallback
13
-
* @param {object} args.
14
-
* @param {string} args.url
15
-
* @param {GitAuth} args.auth
16
-
*
17
-
* @returns {Promise<void>}
13
+
* @param {string} url
14
+
* @param {GitAuth} auth
15
+
* @returns {void | Promise<void>}
18
16
*/
19
17
20
18
/**
@@ -32,7 +30,7 @@ An `onAuthSuccess` function is called with a `{ url, auth }` object.
32
30
const git = require('isomorphic-git')
33
31
git.clone({
34
32
...,
35
-
onAuthSuccess: ({ url, auth }) => {
33
+
onAuthSuccess: (url, auth) => {
36
34
if (confirm('Remember password?')) {
37
35
savedPassword(url, auth)
38
36
}
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@
8
8
"module": "./dist/index.js",
9
9
"exports": {
10
10
".": "./dist/index.cjs",
11
+
"./dist/index.cjs": "./dist/index.cjs",
11
12
"./dist/index.js": "./dist/index.js",
12
13
"./dist/http.cjs": "./dist/http.cjs",
13
14
"./dist/http.js": "./dist/http.js"
@@ -54,6 +55,7 @@
54
55
"dist/bundle.umd.min.js",
55
56
"dist/bundle.umd.min.js.map",
56
57
"dist/http.cjs",
58
+
"dist/http.d.ts",
57
59
"dist/http.js",
58
60
"dist/http.umd.min.js",
59
61
"dist/index.cjs",
Original file line number Diff line number Diff line change
@@ -2,6 +2,36 @@
2
2
import { collect } from '../utils/collect.js'
3
3
import { fromStream } from '../utils/fromStream'
4
4
5
+
// Sorry for the copy & paste from typedefs.js but if we import typedefs.js we'll get a whole bunch of extra comments
6
+
// in the rollup output
7
+
8
+
/**
9
+
* @typedef {Object} GitHttpRequest
10
+
* @property {string} url - The URL to request
11
+
* @property {string} [method='GET'] - The HTTP method to use
12
+
* @property {Object<string, string>} [headers={}] - Headers to include in the HTTP request
13
+
* @property {AsyncIterableIterator<Uint8Array>} [body] - An async iterator of Uint8Arrays that make up the body of POST requests
14
+
* @property {string} [core] - If your `http` plugin needs access to other plugins, it can do so via `git.cores.get(core)`
15
+
* @property {GitEmitterPlugin} [emitter] - If your `http` plugin emits events, it can do so via `emitter.emit()`
16
+
* @property {string} [emitterPrefix] - The `emitterPrefix` passed by the user when calling a function. If your plugin emits events, prefix the event name with this.
17
+
*/
18
+
19
+
/**
20
+
* @typedef {Object} GitHttpResponse
21
+
* @property {string} url - The final URL that was fetched after any redirects
22
+
* @property {string} [method] - The HTTP method that was used
23
+
* @property {Object<string, string>} [headers] - HTTP response headers
24
+
* @property {AsyncIterableIterator<Uint8Array>} [body] - An async iterator of Uint8Arrays that make up the body of the response
25
+
* @property {number} statusCode - The HTTP status code
26
+
* @property {string} statusMessage - The HTTP status message
27
+
*/
28
+
29
+
/**
30
+
* HttpClient
31
+
*
32
+
* @param {GitHttpRequest} request
33
+
* @returns {Promise<GitHttpResponse>}
34
+
*/
5
35
export default async function http({
6
36
onProgress,
7
37
url,
Original file line number Diff line number Diff line change
@@ -2,6 +2,36 @@ import { asyncIteratorToStream } from '../utils/asyncIteratorToStream.js'
2
2
import { collect } from '../utils/collect.js'
3
3
import { fromNodeStream } from '../utils/fromNodeStream.js'
4
4
5
+
// Sorry for the copy & paste from typedefs.js but if we import typedefs.js we'll get a whole bunch of extra comments
6
+
// in the rollup output
7
+
8
+
/**
9
+
* @typedef {Object} GitHttpRequest
10
+
* @property {string} url - The URL to request
11
+
* @property {string} [method='GET'] - The HTTP method to use
12
+
* @property {Object<string, string>} [headers={}] - Headers to include in the HTTP request
13
+
* @property {AsyncIterableIterator<Uint8Array>} [body] - An async iterator of Uint8Arrays that make up the body of POST requests
14
+
* @property {string} [core] - If your `http` plugin needs access to other plugins, it can do so via `git.cores.get(core)`
15
+
* @property {GitEmitterPlugin} [emitter] - If your `http` plugin emits events, it can do so via `emitter.emit()`
16
+
* @property {string} [emitterPrefix] - The `emitterPrefix` passed by the user when calling a function. If your plugin emits events, prefix the event name with this.
17
+
*/
18
+
19
+
/**
20
+
* @typedef {Object} GitHttpResponse
21
+
* @property {string} url - The final URL that was fetched after any redirects
22
+
* @property {string} [method] - The HTTP method that was used
23
+
* @property {Object<string, string>} [headers] - HTTP response headers
24
+
* @property {AsyncIterableIterator<Uint8Array>} [body] - An async iterator of Uint8Arrays that make up the body of the response
25
+
* @property {number} statusCode - The HTTP status code
26
+
* @property {string} statusMessage - The HTTP status message
27
+
*/
28
+
29
+
/**
30
+
* HttpClient
31
+
*
32
+
* @param {GitHttpRequest} request
33
+
* @returns {Promise<GitHttpResponse>}
34
+
*/
5
35
export default async function http({
6
36
onProgress,
7
37
url,
Original file line number Diff line number Diff line change
@@ -83,7 +83,7 @@ export class GitRemoteHTTP {
83
83
// apparently doesn't realize this is a git request and is returning the HTML for the "Azure DevOps Services | Sign In" page.
84
84
if ((res.statusCode === 401 || res.statusCode === 203) && onAuth) {
85
85
// Acquire credentials and try again
86
-
// TODO: read `useHttpPath` value from git config and pass as 2nd argument
86
+
// TODO: read `useHttpPath` value from git config and pass as 2nd argument?
87
87
auth = await onAuth(_origUrl)
88
88
const _auth = calculateBasicAuthUsernamePasswordPair(auth)
89
89
if (_auth) {
@@ -97,9 +97,9 @@ export class GitRemoteHTTP {
97
97
})
98
98
// Tell credential manager if the credentials were no good
99
99
if (res.statusCode === 401 && onAuthFailure) {
100
-
await onAuthFailure({ url: _origUrl, auth })
100
+
await onAuthFailure(_origUrl, auth)
101
101
} else if (res.statusCode === 200 && onAuthSuccess) {
102
-
await onAuthSuccess({ url: _origUrl, auth })
102
+
await onAuthSuccess(_origUrl, auth)
103
103
}
104
104
}
105
105
if (res.statusCode !== 200) {
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4