import { describe, it, expect } from '@ohos/hypium'; import { QiniuToken } from 'platform'; import { util } from '@kit.ArkTS'; export default function QiniuTokenTest() { describe('QiniuTokenTest', () => { it('token_has_three_parts_and_valid_policy', 0, async () => { // AK/SK/bucket 现由调用方注入(本地 app_config + 远程 audio_bucket),单测用固定测试值 const token: string = await QiniuToken.uploadToken('AK_TEST', 'SK_TEST', 'bk_test'); const parts: string[] = token.split(':'); expect(parts.length).assertEqual(3); expect(parts[0]).assertEqual('AK_TEST'); expect(parts[1].length).assertEqual(28); const helper = new util.Base64Helper(); const std: string = parts[2].replace(/-/g, '+').replace(/_/g, '/'); const decoded: Uint8Array = helper.decodeSync(std); const policy: string = String.fromCharCode.apply(null, Array.from(decoded)); expect(policy.indexOf('"scope":"bk_test"') >= 0).assertTrue(); }); }); }