@cloudbase/oauth 0.1.1-alpha → 0.1.1-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Dockerfile +15 -0
- package/README.md +1 -1
- package/_exmaple/assets/scripts/function/function.ts +99 -0
- package/_exmaple/assets/scripts/index.ts +99 -0
- package/_exmaple/assets/scripts/request.ts +11 -0
- package/_exmaple/index.html +15 -0
- package/_exmaple/package.json +33 -0
- package/_exmaple/tsconfig.json +71 -0
- package/_exmaple/typings.d.ts +0 -0
- package/_exmaple/webpack.config.js +42 -0
- package/cdnjs/1.0.0/cloudbase.auth.js +1 -0
- package/cdnjs/1.0.0/cloudbase.database.js +8 -0
- package/cdnjs/1.0.0/cloudbase.full.js +8 -0
- package/cdnjs/1.0.0/cloudbase.functions.js +1 -0
- package/cdnjs/1.0.0/cloudbase.js +1 -0
- package/cdnjs/1.0.0/cloudbase.storage.js +1 -0
- package/cdnjs/1.0.1/cloudbase.auth.js +1 -0
- package/cdnjs/1.0.1/cloudbase.database.js +8 -0
- package/cdnjs/1.0.1/cloudbase.full.js +8 -0
- package/cdnjs/1.0.1/cloudbase.functions.js +1 -0
- package/cdnjs/1.0.1/cloudbase.js +1 -0
- package/cdnjs/1.0.1/cloudbase.storage.js +1 -0
- package/cdnjs/1.0.2/cloudbase.auth.js +1 -0
- package/cdnjs/1.0.2/cloudbase.database.js +8 -0
- package/cdnjs/1.0.2/cloudbase.full.js +8 -0
- package/cdnjs/1.0.2/cloudbase.functions.js +1 -0
- package/cdnjs/1.0.2/cloudbase.js +1 -0
- package/cdnjs/1.0.2/cloudbase.storage.js +1 -0
- package/cdnjs/1.0.3/cloudbase.auth.js +1 -0
- package/cdnjs/1.0.3/cloudbase.database.js +8 -0
- package/cdnjs/1.0.3/cloudbase.full.js +8 -0
- package/cdnjs/1.0.3/cloudbase.functions.js +1 -0
- package/cdnjs/1.0.3/cloudbase.js +1 -0
- package/cdnjs/1.0.3/cloudbase.storage.js +1 -0
- package/cdnjs/1.0.4/cloudbase.auth.js +1 -0
- package/cdnjs/1.0.4/cloudbase.database.js +8 -0
- package/cdnjs/1.0.4/cloudbase.full.js +8 -0
- package/cdnjs/1.0.4/cloudbase.functions.js +1 -0
- package/cdnjs/1.0.4/cloudbase.js +1 -0
- package/cdnjs/1.0.4/cloudbase.storage.js +1 -0
- package/cdnjs/1.1.0/cloudbase.auth.js +1 -0
- package/cdnjs/1.1.0/cloudbase.database.js +8 -0
- package/cdnjs/1.1.0/cloudbase.full.js +8 -0
- package/cdnjs/1.1.0/cloudbase.functions.js +1 -0
- package/cdnjs/1.1.0/cloudbase.js +1 -0
- package/cdnjs/1.1.0/cloudbase.storage.js +1 -0
- package/cdnjs/1.1.1/cloudbase.auth.js +1 -0
- package/cdnjs/1.1.1/cloudbase.database.js +8 -0
- package/cdnjs/1.1.1/cloudbase.full.js +8 -0
- package/cdnjs/1.1.1/cloudbase.functions.js +1 -0
- package/cdnjs/1.1.1/cloudbase.js +1 -0
- package/cdnjs/1.1.1/cloudbase.storage.js +1 -0
- package/cdnjs/1.1.2/cloudbase.auth.js +1 -0
- package/cdnjs/1.1.2/cloudbase.database.js +8 -0
- package/cdnjs/1.1.2/cloudbase.full.js +8 -0
- package/cdnjs/1.1.2/cloudbase.functions.js +1 -0
- package/cdnjs/1.1.2/cloudbase.js +1 -0
- package/cdnjs/1.1.2/cloudbase.storage.js +1 -0
- package/cdnjs/1.1.3/cloudbase.auth.js +1 -0
- package/cdnjs/1.1.3/cloudbase.database.js +8 -0
- package/cdnjs/1.1.3/cloudbase.full.js +8 -0
- package/cdnjs/1.1.3/cloudbase.functions.js +1 -0
- package/cdnjs/1.1.3/cloudbase.js +1 -0
- package/cdnjs/1.1.3/cloudbase.storage.js +1 -0
- package/cdnjs/1.1.4/cloudbase.auth.js +1 -0
- package/cdnjs/1.1.4/cloudbase.database.js +8 -0
- package/cdnjs/1.1.4/cloudbase.full.js +8 -0
- package/cdnjs/1.1.4/cloudbase.functions.js +1 -0
- package/cdnjs/1.1.4/cloudbase.js +1 -0
- package/cdnjs/1.1.4/cloudbase.storage.js +1 -0
- package/cdnjs/1.2.1/cloudbase.auth.js +1 -0
- package/cdnjs/1.2.1/cloudbase.database.js +8 -0
- package/cdnjs/1.2.1/cloudbase.full.js +8 -0
- package/cdnjs/1.2.1/cloudbase.functions.js +1 -0
- package/cdnjs/1.2.1/cloudbase.js +1 -0
- package/cdnjs/1.2.1/cloudbase.storage.js +1 -0
- package/cdnjs/1.2.2/cloudbase.auth.js +1 -0
- package/cdnjs/1.2.2/cloudbase.database.js +8 -0
- package/cdnjs/1.2.2/cloudbase.full.js +8 -0
- package/cdnjs/1.2.2/cloudbase.functions.js +1 -0
- package/cdnjs/1.2.2/cloudbase.js +1 -0
- package/cdnjs/1.2.2/cloudbase.storage.js +1 -0
- package/cdnjs/1.2.3/cloudbase.auth.js +1 -0
- package/cdnjs/1.2.3/cloudbase.database.js +8 -0
- package/cdnjs/1.2.3/cloudbase.full.js +8 -0
- package/cdnjs/1.2.3/cloudbase.functions.js +1 -0
- package/cdnjs/1.2.3/cloudbase.js +1 -0
- package/cdnjs/1.2.3/cloudbase.storage.js +1 -0
- package/cdnjs/1.3.0/cloudbase.auth.js +1 -0
- package/cdnjs/1.3.0/cloudbase.database.js +8 -0
- package/cdnjs/1.3.0/cloudbase.full.js +8 -0
- package/cdnjs/1.3.0/cloudbase.functions.js +1 -0
- package/cdnjs/1.3.0/cloudbase.js +1 -0
- package/cdnjs/1.3.0/cloudbase.realtime.js +1 -0
- package/cdnjs/1.3.0/cloudbase.storage.js +1 -0
- package/cdnjs/1.3.1/cloudbase.auth.js +1 -0
- package/cdnjs/1.3.1/cloudbase.database.js +8 -0
- package/cdnjs/1.3.1/cloudbase.full.js +8 -0
- package/cdnjs/1.3.1/cloudbase.functions.js +1 -0
- package/cdnjs/1.3.1/cloudbase.js +1 -0
- package/cdnjs/1.3.1/cloudbase.realtime.js +1 -0
- package/cdnjs/1.3.1/cloudbase.storage.js +1 -0
- package/cdnjs/1.3.2/cloudbase.auth.js +1 -0
- package/cdnjs/1.3.2/cloudbase.database.js +8 -0
- package/cdnjs/1.3.2/cloudbase.full.js +8 -0
- package/cdnjs/1.3.2/cloudbase.functions.js +1 -0
- package/cdnjs/1.3.2/cloudbase.js +1 -0
- package/cdnjs/1.3.2/cloudbase.realtime.js +1 -0
- package/cdnjs/1.3.2/cloudbase.storage.js +1 -0
- package/cdnjs/1.3.3/cloudbase.auth.js +1 -0
- package/cdnjs/1.3.3/cloudbase.database.js +8 -0
- package/cdnjs/1.3.3/cloudbase.full.js +8 -0
- package/cdnjs/1.3.3/cloudbase.functions.js +1 -0
- package/cdnjs/1.3.3/cloudbase.js +1 -0
- package/cdnjs/1.3.3/cloudbase.realtime.js +1 -0
- package/cdnjs/1.3.3/cloudbase.storage.js +1 -0
- package/cdnjs/1.3.4-alpha.0/cloudbase.auth.js +1 -0
- package/cdnjs/1.3.4-alpha.0/cloudbase.database.js +8 -0
- package/cdnjs/1.3.4-alpha.0/cloudbase.full.js +8 -0
- package/cdnjs/1.3.4-alpha.0/cloudbase.functions.js +1 -0
- package/cdnjs/1.3.4-alpha.0/cloudbase.js +1 -0
- package/cdnjs/1.3.4-alpha.0/cloudbase.realtime.js +1 -0
- package/cdnjs/1.3.4-alpha.0/cloudbase.storage.js +1 -0
- package/cdnjs/1.3.5/cloudbase.analytics.js +1 -0
- package/cdnjs/1.3.5/cloudbase.auth.js +1 -0
- package/cdnjs/1.3.5/cloudbase.database.js +10 -0
- package/cdnjs/1.3.5/cloudbase.full.js +10 -0
- package/cdnjs/1.3.5/cloudbase.functions.js +1 -0
- package/cdnjs/1.3.5/cloudbase.js +1 -0
- package/cdnjs/1.3.5/cloudbase.realtime.js +1 -0
- package/cdnjs/1.3.5/cloudbase.storage.js +1 -0
- package/cdnjs/1.3.5-alpha.0/cloudbase.auth.js +1 -0
- package/cdnjs/1.3.5-alpha.0/cloudbase.database.js +10 -0
- package/cdnjs/1.3.5-alpha.0/cloudbase.full.js +10 -0
- package/cdnjs/1.3.5-alpha.0/cloudbase.functions.js +1 -0
- package/cdnjs/1.3.5-alpha.0/cloudbase.js +1 -0
- package/cdnjs/1.3.5-alpha.0/cloudbase.realtime.js +1 -0
- package/cdnjs/1.3.5-alpha.0/cloudbase.storage.js +1 -0
- package/cdnjs/1.4.0/cloudbase.analytics.js +1 -0
- package/cdnjs/1.4.0/cloudbase.auth.js +1 -0
- package/cdnjs/1.4.0/cloudbase.database.js +10 -0
- package/cdnjs/1.4.0/cloudbase.full.js +10 -0
- package/cdnjs/1.4.0/cloudbase.functions.js +1 -0
- package/cdnjs/1.4.0/cloudbase.js +1 -0
- package/cdnjs/1.4.0/cloudbase.realtime.js +1 -0
- package/cdnjs/1.4.0/cloudbase.storage.js +1 -0
- package/cdnjs/1.4.1/cloudbase.analytics.js +1 -0
- package/cdnjs/1.4.1/cloudbase.auth.js +1 -0
- package/cdnjs/1.4.1/cloudbase.database.js +10 -0
- package/cdnjs/1.4.1/cloudbase.full.js +10 -0
- package/cdnjs/1.4.1/cloudbase.functions.js +1 -0
- package/cdnjs/1.4.1/cloudbase.js +1 -0
- package/cdnjs/1.4.1/cloudbase.realtime.js +1 -0
- package/cdnjs/1.4.1/cloudbase.storage.js +1 -0
- package/cdnjs/1.4.1-alpha.0/cloudbase.analytics.js +1 -0
- package/cdnjs/1.4.1-alpha.0/cloudbase.auth.js +1 -0
- package/cdnjs/1.4.1-alpha.0/cloudbase.database.js +10 -0
- package/cdnjs/1.4.1-alpha.0/cloudbase.full.js +10 -0
- package/cdnjs/1.4.1-alpha.0/cloudbase.functions.js +1 -0
- package/cdnjs/1.4.1-alpha.0/cloudbase.js +1 -0
- package/cdnjs/1.4.1-alpha.0/cloudbase.realtime.js +1 -0
- package/cdnjs/1.4.1-alpha.0/cloudbase.storage.js +1 -0
- package/cdnjs/1.4.2-alpha.0/cloudbase.analytics.js +1 -0
- package/cdnjs/1.4.2-alpha.0/cloudbase.auth.js +1 -0
- package/cdnjs/1.4.2-alpha.0/cloudbase.database.js +10 -0
- package/cdnjs/1.4.2-alpha.0/cloudbase.full.js +10 -0
- package/cdnjs/1.4.2-alpha.0/cloudbase.functions.js +1 -0
- package/cdnjs/1.4.2-alpha.0/cloudbase.js +1 -0
- package/cdnjs/1.4.2-alpha.0/cloudbase.realtime.js +1 -0
- package/cdnjs/1.4.2-alpha.0/cloudbase.storage.js +1 -0
- package/cdnjs/1.5.0/cloudbase.analytics.js +1 -0
- package/cdnjs/1.5.0/cloudbase.auth.js +1 -0
- package/cdnjs/1.5.0/cloudbase.database.js +10 -0
- package/cdnjs/1.5.0/cloudbase.full.js +10 -0
- package/cdnjs/1.5.0/cloudbase.functions.js +1 -0
- package/cdnjs/1.5.0/cloudbase.js +1 -0
- package/cdnjs/1.5.0/cloudbase.realtime.js +1 -0
- package/cdnjs/1.5.0/cloudbase.storage.js +1 -0
- package/cdnjs/1.5.1/cloudbase.analytics.js +1 -0
- package/cdnjs/1.5.1/cloudbase.auth.js +1 -0
- package/cdnjs/1.5.1/cloudbase.database.js +26 -0
- package/cdnjs/1.5.1/cloudbase.full.js +26 -0
- package/cdnjs/1.5.1/cloudbase.functions.js +1 -0
- package/cdnjs/1.5.1/cloudbase.js +1 -0
- package/cdnjs/1.5.1/cloudbase.realtime.js +1 -0
- package/cdnjs/1.5.1/cloudbase.storage.js +1 -0
- package/cdnjs/1.5.1-alpha.0/cloudbase.analytics.js +1 -0
- package/cdnjs/1.5.1-alpha.0/cloudbase.auth.js +1 -0
- package/cdnjs/1.5.1-alpha.0/cloudbase.database.js +10 -0
- package/cdnjs/1.5.1-alpha.0/cloudbase.full.js +10 -0
- package/cdnjs/1.5.1-alpha.0/cloudbase.functions.js +1 -0
- package/cdnjs/1.5.1-alpha.0/cloudbase.js +1 -0
- package/cdnjs/1.5.1-alpha.0/cloudbase.realtime.js +1 -0
- package/cdnjs/1.5.1-alpha.0/cloudbase.storage.js +1 -0
- package/cdnjs/1.5.3-alpha.0/cloudbase.analytics.js +1 -0
- package/cdnjs/1.5.3-alpha.0/cloudbase.auth.js +1 -0
- package/cdnjs/1.5.3-alpha.0/cloudbase.database.js +26 -0
- package/cdnjs/1.5.3-alpha.0/cloudbase.full.js +26 -0
- package/cdnjs/1.5.3-alpha.0/cloudbase.functions.js +1 -0
- package/cdnjs/1.5.3-alpha.0/cloudbase.js +1 -0
- package/cdnjs/1.5.3-alpha.0/cloudbase.realtime.js +1 -0
- package/cdnjs/1.5.3-alpha.0/cloudbase.storage.js +1 -0
- package/cdnjs/1.6.0/cloudbase.analytics.js +1 -0
- package/cdnjs/1.6.0/cloudbase.auth.js +1 -0
- package/cdnjs/1.6.0/cloudbase.database.js +26 -0
- package/cdnjs/1.6.0/cloudbase.full.js +26 -0
- package/cdnjs/1.6.0/cloudbase.functions.js +1 -0
- package/cdnjs/1.6.0/cloudbase.js +1 -0
- package/cdnjs/1.6.0/cloudbase.realtime.js +1 -0
- package/cdnjs/1.6.0/cloudbase.storage.js +1 -0
- package/{CHANGELOG.md → changelog.md} +0 -0
- package/dist/README.md +153 -0
- package/{app → dist/app}/index.d.ts +1 -0
- package/{app → dist/app}/index.js +0 -0
- package/dist/app/index.js.map +1 -0
- package/{app → dist/app}/internal.d.ts +0 -0
- package/{app → dist/app}/internal.js +0 -0
- package/{app → dist/app}/internal.js.map +0 -0
- package/{app → dist/app}/openuri.d.ts +0 -0
- package/{app → dist/app}/openuri.js +2 -1
- package/{app → dist/app}/openuri.js.map +1 -1
- package/{app → dist/app}/request.d.ts +4 -3
- package/{app → dist/app}/request.js +20 -12
- package/dist/app/request.js.map +1 -0
- package/{app → dist/app}/storage.d.ts +0 -0
- package/{app → dist/app}/storage.js +0 -0
- package/{app → dist/app}/storage.js.map +0 -0
- package/{auth → dist/auth}/consts.d.ts +21 -4
- package/{auth → dist/auth}/consts.js +27 -5
- package/dist/auth/consts.js.map +1 -0
- package/{auth → dist/auth}/index.d.ts +83 -34
- package/{auth → dist/auth}/index.js +239 -92
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/models.d.ts +284 -0
- package/{oauthclient → dist/auth}/models.js +1 -0
- package/dist/auth/models.js.map +1 -0
- package/{captcha → dist/captcha}/index.d.ts +0 -0
- package/{captcha → dist/captcha}/index.js +4 -2
- package/dist/captcha/index.js.map +1 -0
- package/dist/changelog.md +30 -0
- package/dist/function/index.d.ts +38 -0
- package/dist/function/index.js +80 -0
- package/dist/function/index.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/{oauthclient → dist/oauthclient}/consts.d.ts +0 -0
- package/{oauthclient → dist/oauthclient}/consts.js +0 -0
- package/{oauthclient → dist/oauthclient}/consts.js.map +0 -0
- package/{oauthclient → dist/oauthclient}/index.d.ts +0 -0
- package/{oauthclient → dist/oauthclient}/index.js +2 -2
- package/dist/oauthclient/index.js.map +1 -0
- package/{oauthclient → dist/oauthclient}/interface.d.ts +4 -0
- package/{oauthclient → dist/oauthclient}/interface.js +0 -0
- package/{oauthclient → dist/oauthclient}/interface.js.map +1 -1
- package/{oauthclient → dist/oauthclient}/models.d.ts +12 -11
- package/{auth → dist/oauthclient}/models.js +0 -0
- package/{oauthclient → dist/oauthclient}/models.js.map +0 -0
- package/{oauthclient → dist/oauthclient}/oauthclient.d.ts +11 -7
- package/{oauthclient → dist/oauthclient}/oauthclient.js +27 -12
- package/dist/oauthclient/oauthclient.js.map +1 -0
- package/dist/package.json +32 -0
- package/{utils/single-promise.d.ts → dist/utils/promise.d.ts} +3 -3
- package/{utils/single-promise.js → dist/utils/promise.js} +6 -6
- package/dist/utils/promise.js.map +1 -0
- package/{utils → dist/utils}/uuid.d.ts +0 -0
- package/{utils → dist/utils}/uuid.js +0 -0
- package/{utils → dist/utils}/uuid.js.map +0 -0
- package/docs/dev.md +71 -0
- package/docs/errlog.md +79 -0
- package/package.json +3 -2
- package/publish.sh +2 -0
- package/src/app/index.ts +83 -0
- package/src/app/internal.ts +26 -0
- package/src/app/openuri.ts +111 -0
- package/src/app/request.ts +66 -0
- package/src/app/storage.ts +58 -0
- package/src/auth/consts.ts +74 -0
- package/src/auth/index.ts +718 -0
- package/src/auth/models.ts +352 -0
- package/src/captcha/index.ts +170 -0
- package/src/function/index.ts +103 -0
- package/src/index.ts +32 -0
- package/src/oauthclient/consts.ts +48 -0
- package/src/oauthclient/index.ts +33 -0
- package/src/oauthclient/interface.ts +34 -0
- package/src/oauthclient/models.ts +50 -0
- package/src/oauthclient/oauthclient.ts +487 -0
- package/src/utils/promise.ts +41 -0
- package/src/utils/uuid.ts +11 -0
- package/test/e2e/cases/custom-login.test.js +122 -0
- package/test/e2e/cases/index.test.js +61 -0
- package/test/e2e/cases/login-state.test.js +89 -0
- package/test/e2e/environment.js +39 -0
- package/test/e2e/global_setup.js +33 -0
- package/test/e2e/global_teardown.js +15 -0
- package/test/e2e/setup.js +37 -0
- package/test/unit/index.test.js +89 -0
- package/test/web/cases/auth/index.js +256 -0
- package/test/web/cases/database/collection.js +173 -0
- package/test/web/cases/database/command.js +754 -0
- package/test/web/cases/database/date.js +122 -0
- package/test/web/cases/database/db.js +20 -0
- package/test/web/cases/database/document.js +160 -0
- package/test/web/cases/database/geo-advanced.js +327 -0
- package/test/web/cases/database/geo.js +105 -0
- package/test/web/cases/database/index.js +315 -0
- package/test/web/cases/database/order.js +83 -0
- package/test/web/cases/database/realtime.js +102 -0
- package/test/web/cases/database/regex.js +140 -0
- package/test/web/cases/ext/index.js +88 -0
- package/test/web/cases/function/index.js +77 -0
- package/test/web/cases/storage/cos.jpeg +0 -0
- package/test/web/cases/storage/index.js +207 -0
- package/test/web/index.html +63 -0
- package/test/web/index.js +109 -0
- package/test/web/util.js +80 -0
- package/tsconfig.json +35 -0
- package/wiki/README.md +75 -0
- package/app/index.js.map +0 -1
- package/app/request.js.map +0 -1
- package/auth/consts.js.map +0 -1
- package/auth/index.js.map +0 -1
- package/auth/models.d.ts +0 -158
- package/auth/models.js.map +0 -1
- package/captcha/index.js.map +0 -1
- package/index.d.ts +0 -8
- package/index.js +0 -17
- package/index.js.map +0 -1
- package/oauthclient/index.js.map +0 -1
- package/oauthclient/oauthclient.js.map +0 -1
- package/utils/single-promise.js.map +0 -1
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
// auth
|
|
2
|
+
import axios from "axios"
|
|
3
|
+
import * as assert from "power-assert"
|
|
4
|
+
import { authFnUrl, env } from "../../../../test.config.js"
|
|
5
|
+
import {
|
|
6
|
+
register,
|
|
7
|
+
callbackWithTryCatch,
|
|
8
|
+
isSuccess,
|
|
9
|
+
printSuccess
|
|
10
|
+
} from "../../util"
|
|
11
|
+
|
|
12
|
+
function registerAuthTest(app, appid, scope) {
|
|
13
|
+
let auth = app.auth({
|
|
14
|
+
persistence: "local"
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
register("auth: getUserInfo, scope: " + scope, async () => {
|
|
18
|
+
await auth
|
|
19
|
+
.getUserInfo()
|
|
20
|
+
.then(
|
|
21
|
+
callbackWithTryCatch((res) => {
|
|
22
|
+
assert(isSuccess(0, res) && res.appid, { res })
|
|
23
|
+
})
|
|
24
|
+
)
|
|
25
|
+
.catch(
|
|
26
|
+
callbackWithTryCatch((err) => {
|
|
27
|
+
assert(false, { err })
|
|
28
|
+
})
|
|
29
|
+
)
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
register("auth: signOut, scope: " + scope, async () => {
|
|
33
|
+
await auth
|
|
34
|
+
.signOut()
|
|
35
|
+
.then(
|
|
36
|
+
callbackWithTryCatch((res) => {
|
|
37
|
+
assert(isSuccess(0, res) && res.appid, { res })
|
|
38
|
+
})
|
|
39
|
+
)
|
|
40
|
+
.catch(
|
|
41
|
+
callbackWithTryCatch((err) => {
|
|
42
|
+
assert(false, { err })
|
|
43
|
+
})
|
|
44
|
+
)
|
|
45
|
+
})
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export async function registerAuthCases(auth, ...args) {
|
|
49
|
+
const loginState = await auth.getLoginState()
|
|
50
|
+
switch (true) {
|
|
51
|
+
case loginState.isAnonymousAuth:
|
|
52
|
+
return registerAuthCasesOfAnonymous(auth, ...args)
|
|
53
|
+
case loginState.isCustomAuth:
|
|
54
|
+
return registerAuthCasesOfCustom(auth, ...args)
|
|
55
|
+
case loginState.isWeixinAuth:
|
|
56
|
+
return registerAuthCasesOfWxWeb(auth, ...args)
|
|
57
|
+
case loginState.isUsernameAuth:
|
|
58
|
+
return registerAuthCasesOfUsername(auth, ...args)
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function registerCase(msg, fn) {
|
|
62
|
+
register("auth", msg, fn)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function registerAuthCasesOfWxWeb(auth) {
|
|
66
|
+
registerCase("auth: weixin loginState", async () => {
|
|
67
|
+
const loginState = await auth.getLoginState()
|
|
68
|
+
assert(isSuccess(0, loginState), { loginState })
|
|
69
|
+
assert(loginState.isWeixinAuth === true, { loginState })
|
|
70
|
+
assert(loginState.user.loginType === "CUSTOM", { loginState })
|
|
71
|
+
})
|
|
72
|
+
}
|
|
73
|
+
function registerAuthCasesOfCustom(auth) {
|
|
74
|
+
registerCase("auth: custom loginState", async () => {
|
|
75
|
+
const loginState = await auth.getLoginState()
|
|
76
|
+
assert(isSuccess(0, loginState), { loginState })
|
|
77
|
+
assert(loginState.isCustomAuth === true, { loginState })
|
|
78
|
+
assert(loginState.user.loginType === "CUSTOM", { loginState })
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
registerCase("auth: anonymous storage info", () => {
|
|
82
|
+
const loginTypeInfo = localStorage.getItem(`login_type_${env}`)
|
|
83
|
+
assert(loginTypeInfo && JSON.parse(loginTypeInfo).content === "CUSTOM")
|
|
84
|
+
})
|
|
85
|
+
}
|
|
86
|
+
function registerAuthCasesOfAnonymous(auth) {
|
|
87
|
+
registerCase("auth: anonymous loginState", async () => {
|
|
88
|
+
const loginState = await auth.getLoginState()
|
|
89
|
+
assert(isSuccess(0, loginState), { loginState })
|
|
90
|
+
assert(loginState.isAnonymousAuth === true, { loginState })
|
|
91
|
+
assert(loginState.user.loginType === "ANONYMOUS", { loginState })
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
registerCase("auth: anonymous storage info", () => {
|
|
95
|
+
const uidInfo = localStorage.getItem(`anonymous_uuid_${env}`)
|
|
96
|
+
const loginTypeInfo = localStorage.getItem(`login_type_${env}`)
|
|
97
|
+
assert(uidInfo && JSON.parse(uidInfo).content.length > 0)
|
|
98
|
+
assert(loginTypeInfo && JSON.parse(loginTypeInfo).content === "ANONYMOUS")
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
registerCase("auth: anonymous cant't signOut", async () => {
|
|
102
|
+
let res
|
|
103
|
+
try {
|
|
104
|
+
await auth.signOut()
|
|
105
|
+
} catch (e) {
|
|
106
|
+
res = e
|
|
107
|
+
}
|
|
108
|
+
assert.strictEqual(JSON.parse(res.message).code, "INVALID_OPERATION", {
|
|
109
|
+
res
|
|
110
|
+
})
|
|
111
|
+
})
|
|
112
|
+
}
|
|
113
|
+
function registerAuthCasesOfUsername(auth, username) {
|
|
114
|
+
registerCase("auth: username basic info", async () => {
|
|
115
|
+
const userinfo = await auth.getUserInfo()
|
|
116
|
+
assert(userinfo.loginType === "USERNAME", { userinfo })
|
|
117
|
+
assert(userinfo.username === username, { userinfo })
|
|
118
|
+
})
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
async function getTicket() {
|
|
122
|
+
return (await axios.get(authFnUrl)).data
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export async function signInCustom(auth) {
|
|
126
|
+
const loginState = await auth.getLoginState()
|
|
127
|
+
if (loginState && !loginState.isCustomAuth) {
|
|
128
|
+
alert("当前已有其他登录类型的登录态,请清空localstorage后重新发起测试")
|
|
129
|
+
return
|
|
130
|
+
}
|
|
131
|
+
const ticket = await getTicket()
|
|
132
|
+
await auth.customAuthProvider().signIn(ticket)
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export async function signInAnonymous(auth) {
|
|
136
|
+
const loginState = await auth.getLoginState()
|
|
137
|
+
if (loginState && !loginState.isAnonymousAuth) {
|
|
138
|
+
alert("当前已有其他登录类型的登录态,请清空localstorage后重新发起测试")
|
|
139
|
+
return
|
|
140
|
+
}
|
|
141
|
+
await auth.anonymousAuthProvider().signIn()
|
|
142
|
+
|
|
143
|
+
// // 匿名登录后,再updateEmail测试
|
|
144
|
+
// const updateEmailRes = await auth.currentUser.updateEmail(
|
|
145
|
+
// "2420367792@qq.com",
|
|
146
|
+
// "123456789aaaa"
|
|
147
|
+
// )
|
|
148
|
+
// console.log("updateEmailRes", updateEmailRes)
|
|
149
|
+
|
|
150
|
+
// // 邮箱登录
|
|
151
|
+
// const loginByEmailRes = await auth.signInWithEmailAndPassword(
|
|
152
|
+
// "2420367792@qq.com",
|
|
153
|
+
// "123456789aaaa"
|
|
154
|
+
// )
|
|
155
|
+
// console.log("loginByEmailRes", loginByEmailRes)
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export async function signInByPhone(auth, phoneNumber) {
|
|
159
|
+
const loginState = await auth.getLoginState()
|
|
160
|
+
if (loginState && !loginState.isPhoneAuth) {
|
|
161
|
+
alert("当前已有其他登录类型的登录态,请清空localstorage后重新发起测试")
|
|
162
|
+
return
|
|
163
|
+
}
|
|
164
|
+
// await auth.anonymousAuthProvider().signIn();
|
|
165
|
+
|
|
166
|
+
console.log("auth", auth)
|
|
167
|
+
|
|
168
|
+
// // 1. 发送验证码
|
|
169
|
+
// const getCodeRes = await auth.sendPhoneCode(phoneNumber)
|
|
170
|
+
// console.log("getCodeRes", getCodeRes)
|
|
171
|
+
// 2. 验证码+密码注册
|
|
172
|
+
// const signUpRes = await auth.signUpWithPhoneCode(
|
|
173
|
+
// phoneNumber,
|
|
174
|
+
// "293791",
|
|
175
|
+
// "33333333ll"
|
|
176
|
+
// )
|
|
177
|
+
// console.log("signInRes", signUpRes)
|
|
178
|
+
// 3. 验证码登录
|
|
179
|
+
// const signInRes1 = await auth.phoneAuthProvider().signIn({
|
|
180
|
+
// phoneNumber,
|
|
181
|
+
// phoneCode: "293791"
|
|
182
|
+
// })
|
|
183
|
+
|
|
184
|
+
// 4. 密码登录
|
|
185
|
+
// const signInRes2 = await auth.phoneAuthProvider().signIn({
|
|
186
|
+
// phoneNumber,
|
|
187
|
+
// password: "abc123456"
|
|
188
|
+
// })
|
|
189
|
+
// console.log("signInRes2", signInRes2)
|
|
190
|
+
// console.log("signInRes1", signInRes1)
|
|
191
|
+
|
|
192
|
+
// 5. 更新手机号
|
|
193
|
+
// const user = await auth.getCurrenUser()
|
|
194
|
+
// const user = auth.currentUser
|
|
195
|
+
// console.log('auth', auth)
|
|
196
|
+
// console.log("user", user)
|
|
197
|
+
// const updatePhoneRes1 = await user.updatePhoneNumber(18202741638, '892693')
|
|
198
|
+
// console.log('updatePhoneRes1', updatePhoneRes1)
|
|
199
|
+
// const updateUseInfo1 = await auth.getUserInfo()
|
|
200
|
+
// console.log('updateUseInfo1', updateUseInfo1)
|
|
201
|
+
|
|
202
|
+
// 6. 解绑手机号
|
|
203
|
+
// const unlinkRes = await user.unlink("PHONE")
|
|
204
|
+
// console.log("unlinkRes", unlinkRes)
|
|
205
|
+
|
|
206
|
+
// 强制重置手机号密码
|
|
207
|
+
// const forceUpdateRes = await auth.forceResetPwdByPhoneCode({
|
|
208
|
+
// phoneNumber,
|
|
209
|
+
// phoneCode: "581307",
|
|
210
|
+
// password: "abc123456"
|
|
211
|
+
// })
|
|
212
|
+
|
|
213
|
+
// console.log("forceUpdateRes", forceUpdateRes)
|
|
214
|
+
// const user = await auth.getCurrenUser()
|
|
215
|
+
// console.log("user", user)
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export async function signInWeixin(auth, appid) {
|
|
219
|
+
const provider = auth.weixinAuthProvider({
|
|
220
|
+
appid,
|
|
221
|
+
// scope: "snsapi_userinfo"
|
|
222
|
+
scope: "snsapi_login"
|
|
223
|
+
})
|
|
224
|
+
const result = await provider.getRedirectResult()
|
|
225
|
+
if (result) {
|
|
226
|
+
printSuccess(result)
|
|
227
|
+
} else {
|
|
228
|
+
provider.signInWithRedirect()
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export async function signInWithUsername(auth, { username, password }) {
|
|
233
|
+
if (!username || !password) {
|
|
234
|
+
throw new Error("请配置用户名&密码")
|
|
235
|
+
}
|
|
236
|
+
const loginState = await auth.getLoginState()
|
|
237
|
+
if (loginState && !loginState.isAnonymousAuth) {
|
|
238
|
+
alert("当前已有其他登录类型的登录态,请清空localstorage后重新发起测试")
|
|
239
|
+
return
|
|
240
|
+
}
|
|
241
|
+
// 检查用户名是否绑定过
|
|
242
|
+
if (!(await auth.isUsernameRegistered(username))) {
|
|
243
|
+
await signInCustom(auth)
|
|
244
|
+
await auth.currentUser.updateUsername(username) // 绑定用户名
|
|
245
|
+
} else {
|
|
246
|
+
await auth.signInWithUsernameAndPassword(username, password)
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
export async function clearLoginState() {
|
|
251
|
+
try {
|
|
252
|
+
await auth.signOut()
|
|
253
|
+
} catch (e) {
|
|
254
|
+
localStorage.clear()
|
|
255
|
+
}
|
|
256
|
+
}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/*eslint max-nested-callbacks: 0 */
|
|
2
|
+
import * as assert from 'power-assert';
|
|
3
|
+
import { isSuccess, callbackWithTryCatch, catchCallback } from '../../util';
|
|
4
|
+
import { registerCase } from '.';
|
|
5
|
+
|
|
6
|
+
export function registerCollection(app, collName) {
|
|
7
|
+
const db = app.database();
|
|
8
|
+
console.log(db);
|
|
9
|
+
const collection = db.collection(collName);
|
|
10
|
+
|
|
11
|
+
registerCase('database collection: name test', callbackWithTryCatch(() => {
|
|
12
|
+
assert(collection.name === collName);
|
|
13
|
+
}));
|
|
14
|
+
|
|
15
|
+
registerCase('database collection: add one doc, update and remove with callback', async () => {
|
|
16
|
+
await new Promise(resolve => {
|
|
17
|
+
collection.add({ a: 1 }, (err, res) => {
|
|
18
|
+
try {
|
|
19
|
+
assert(isSuccess(err, res), { err, res });
|
|
20
|
+
assert(isSuccess(0, res) && res.id, { err, res });
|
|
21
|
+
assert(isSuccess(0, res) && res.requestId, { err, res });
|
|
22
|
+
|
|
23
|
+
let id = res.id;
|
|
24
|
+
|
|
25
|
+
collection.doc(id).update({ age: 18 }, (err, res) => {
|
|
26
|
+
try {
|
|
27
|
+
assert(isSuccess(err, res), { err, res });
|
|
28
|
+
assert(isSuccess(0, res) && res.updated > 0, { err, res });
|
|
29
|
+
|
|
30
|
+
collection.doc(id).remove(callbackWithTryCatch((err, res) => {
|
|
31
|
+
assert(isSuccess(err, res), { err, res });
|
|
32
|
+
assert(isSuccess(0, res) && res.deleted, { err, res });
|
|
33
|
+
assert(isSuccess(0, res) && res.requestId, { err, res });
|
|
34
|
+
}, () => {
|
|
35
|
+
resolve();
|
|
36
|
+
}));
|
|
37
|
+
} catch (e) {
|
|
38
|
+
catchCallback(e);
|
|
39
|
+
resolve();
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
} catch (e) {
|
|
43
|
+
catchCallback(e);
|
|
44
|
+
resolve();
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
registerCase('database collection: add one doc, update and remove with promise', async () => {
|
|
51
|
+
await new Promise(async resolve => {
|
|
52
|
+
await collection.add({ a: 1 }).then(res => {
|
|
53
|
+
try {
|
|
54
|
+
assert(isSuccess(0, res), { res });
|
|
55
|
+
assert(isSuccess(0, res) && res.id, { res });
|
|
56
|
+
assert(isSuccess(0, res) && res.requestId, { res });
|
|
57
|
+
|
|
58
|
+
let id = res.id;
|
|
59
|
+
collection.doc(id).update({ age: 18 }).then(res => {
|
|
60
|
+
try {
|
|
61
|
+
assert(isSuccess(0, res), { res });
|
|
62
|
+
assert(isSuccess(0, res) && res.updated > 0, { res });
|
|
63
|
+
|
|
64
|
+
collection.doc(id).remove().then(callbackWithTryCatch(res => {
|
|
65
|
+
assert(isSuccess(0, res), { res });
|
|
66
|
+
assert(isSuccess(0, res) && res.deleted, { res });
|
|
67
|
+
assert(isSuccess(0, res) && res.requestId, { res });
|
|
68
|
+
}, () => {
|
|
69
|
+
resolve();
|
|
70
|
+
})).catch(callbackWithTryCatch(err => {
|
|
71
|
+
assert(false, { err });
|
|
72
|
+
}, () => {
|
|
73
|
+
resolve();
|
|
74
|
+
}));
|
|
75
|
+
} catch (e) {
|
|
76
|
+
catchCallback(e);
|
|
77
|
+
resolve();
|
|
78
|
+
}
|
|
79
|
+
}).catch(callbackWithTryCatch(err => {
|
|
80
|
+
assert(false, { err });
|
|
81
|
+
}, () => {
|
|
82
|
+
resolve();
|
|
83
|
+
}));
|
|
84
|
+
} catch (e) {
|
|
85
|
+
catchCallback(e);
|
|
86
|
+
resolve();
|
|
87
|
+
}
|
|
88
|
+
}).catch(callbackWithTryCatch(err => {
|
|
89
|
+
assert(false, { err });
|
|
90
|
+
}, () => {
|
|
91
|
+
resolve();
|
|
92
|
+
}));
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
registerCase('database collection: API - get all data', async () => {
|
|
97
|
+
await collection.get().then(callbackWithTryCatch(res => {
|
|
98
|
+
assert(Array.isArray(res.data), { res });
|
|
99
|
+
})).catch(callbackWithTryCatch(err => {
|
|
100
|
+
assert(false, { err });
|
|
101
|
+
}));
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
registerCase('database collection: API - use orderBy', async () => {
|
|
105
|
+
const field = 'huming';
|
|
106
|
+
const direction = 'asc';
|
|
107
|
+
await collection.orderBy(field, direction).get().then(callbackWithTryCatch(res => {
|
|
108
|
+
assert(Array.isArray(res.data), { res });
|
|
109
|
+
})).catch(callbackWithTryCatch(err => {
|
|
110
|
+
assert(false, { err });
|
|
111
|
+
}));
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
registerCase('database collection: API - use limit', async () => {
|
|
115
|
+
const limit = 1;
|
|
116
|
+
await collection.limit(limit).get().then(callbackWithTryCatch(res => {
|
|
117
|
+
assert(Array.isArray(res.data), { res });
|
|
118
|
+
})).catch(callbackWithTryCatch(err => {
|
|
119
|
+
assert(false, { err });
|
|
120
|
+
}));
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
registerCase('database collection: API - use offset', async () => {
|
|
124
|
+
const offset = 2;
|
|
125
|
+
await collection.skip(offset).get().then(callbackWithTryCatch(res => {
|
|
126
|
+
assert(Array.isArray(res.data), { res });
|
|
127
|
+
})).catch(callbackWithTryCatch(err => {
|
|
128
|
+
assert(false, { err });
|
|
129
|
+
}));
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
registerCase('database collection: API - use field', async () => {
|
|
133
|
+
await collection.field({ 'age': 1 }).get().then(callbackWithTryCatch(res => {
|
|
134
|
+
assert(Array.isArray(res.data), { res });
|
|
135
|
+
})).catch(callbackWithTryCatch(err => {
|
|
136
|
+
assert(false, { err });
|
|
137
|
+
}));
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
registerCase('database collection: API - add and remove with skip', async () => {
|
|
141
|
+
return new Promise(async resolve => {
|
|
142
|
+
try {
|
|
143
|
+
const text = 'test for add and remove with skip';
|
|
144
|
+
let i = 0;
|
|
145
|
+
while (i++ < 10) {
|
|
146
|
+
await collection.add({
|
|
147
|
+
text
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
let res = await collection.where({
|
|
152
|
+
text
|
|
153
|
+
}).get();
|
|
154
|
+
|
|
155
|
+
assert(isSuccess(0, res) && res.data.length > 0, { res });
|
|
156
|
+
|
|
157
|
+
await collection.where({
|
|
158
|
+
text
|
|
159
|
+
}).remove();
|
|
160
|
+
|
|
161
|
+
res = await collection.where({
|
|
162
|
+
text
|
|
163
|
+
}).get();
|
|
164
|
+
|
|
165
|
+
assert(isSuccess(0, res) && res.data.length === 0, { res });
|
|
166
|
+
} catch (e) {
|
|
167
|
+
catchCallback(e);
|
|
168
|
+
} finally {
|
|
169
|
+
resolve();
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
}
|