Repository navigation
fix(web-ui): validate provider modal input #80
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
9e4cb1b
fix(web-ui): validate provider modal input
awsldev 8bb9a2a
test(web-ui): relax parity baseline drift assertions
awsldev 563f0ee
fix(web-ui): harden usage tab rendering
awsldev 1f28abe
fix(web-ui): use production vue runtime
awsldev 47b291f
docs(readme): update reset command examples
awsldev 915b764
fix(usage): skip session detail loading for charts
awsldev f16a61d
fix(provider): persist normalized urls on add
awsldev 657e95c
fix(reset): silence git repo probe output
awsldev 6b441c0
fix(usage): decouple charts from heavy session loads
awsldev 48ac808
fix(openclaw): sync default config with live file
awsldev 1a1ff13
fix(openclaw): read provider fields from legacy shapes
awsldev bb27952
fix(openclaw): fallback to sole provider config
awsldev a06f44b
fix(openclaw): show structured provider refs in quick form
awsldev 9096a81
refactor(openclaw): remove add-config button from tab
awsldev 07be648
fix(openclaw): align config reading with official secret fields
awsldev a1fd9a8
fix(openclaw): normalize provider lookup in quick form
awsldev 62e1b24
fix(openclaw): surface auth profile fallback in quick form
awsldev 50381f8
fix(openclaw): make external auth values visible and editable
awsldev 265bfe4
perf(sessions): defer detail hydration on tab switch
awsldev 2e82f22
perf(sessions): batch session list rendering on demand
awsldev 7621627
fix(cli): remove duplicate isPlainObject helper
awsldev 9eab383
fix(web-ui): restore session browser runtime
ymkiux 4dff290
fix(web-ui): align session browser implementation
ymkiux b9e6da2
test(web-ui): sync parity drift expectations
ymkiux de4ac6a
fix(openclaw): redact secrets and harden session usage
ymkiux File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| import assert from 'assert'; | ||
| import { createProvidersMethods } from '../../web-ui/modules/app.methods.providers.mjs'; | ||
|
|
||
| function createContext(overrides = {}, apiImpl = async () => ({ success: true })) { | ||
| const messages = []; | ||
| const loadAllCalls = []; | ||
| const methods = createProvidersMethods({ api: apiImpl }); | ||
| const context = { | ||
| providersList: [], | ||
| codexAuthProfiles: [], | ||
| showAddModal: true, | ||
| showEditModal: false, | ||
| resetConfigLoading: false, | ||
| newProvider: { name: '', url: '', key: '' }, | ||
| editingProvider: { name: '', url: '', key: '', readOnly: false, nonEditable: false }, | ||
| claudeConfigs: {}, | ||
| showMessage(text, type) { | ||
| messages.push({ text: String(text), type: type || 'info' }); | ||
| }, | ||
| async loadAll() { | ||
| loadAllCalls.push('loadAll'); | ||
| }, | ||
| ...methods, | ||
| ...overrides | ||
| }; | ||
| return { context, messages, loadAllCalls }; | ||
| } | ||
|
|
||
| test('provider validation rejects invalid add-provider fields before submit', async () => { | ||
| const apiCalls = []; | ||
| const { context, messages } = createContext({ | ||
| newProvider: { | ||
| name: 'bad name', | ||
| url: 'not-a-url', | ||
| key: 'sk-test' | ||
| } | ||
| }, async (action, params) => { | ||
| apiCalls.push({ action, params }); | ||
| return { success: true }; | ||
| }); | ||
|
|
||
| assert.strictEqual(context.canSubmitProvider('add'), false); | ||
| assert.strictEqual(context.providerFieldError('add', 'name'), '名称仅支持字母/数字/._-'); | ||
| assert.strictEqual(context.providerFieldError('add', 'url'), 'URL 仅支持 http/https'); | ||
|
|
||
| await context.addProvider(); | ||
|
|
||
| assert.deepStrictEqual(apiCalls, []); | ||
| assert.strictEqual(messages.length, 1); | ||
| assert.deepStrictEqual(messages[0], { | ||
| text: '名称仅支持字母/数字/._-', | ||
| type: 'error' | ||
| }); | ||
| }); | ||
|
|
||
| test('addProvider normalizes trimmed values and submits sanitized payload', async () => { | ||
| const apiCalls = []; | ||
| const { context, messages, loadAllCalls } = createContext({ | ||
| providersList: [{ name: 'alpha', url: 'https://alpha.example.com/v1', hasKey: true }], | ||
| newProvider: { | ||
| name: ' beta.provider ', | ||
| url: ' https://api.example.com/v1/ ', | ||
| key: ' sk-live ' | ||
| } | ||
| }, async (action, params) => { | ||
| apiCalls.push({ action, params }); | ||
| return { success: true }; | ||
| }); | ||
|
|
||
| await context.addProvider(); | ||
|
|
||
| assert.deepStrictEqual(apiCalls, [{ | ||
| action: 'add-provider', | ||
| params: { | ||
| name: 'beta.provider', | ||
| url: 'https://api.example.com/v1', | ||
| key: ' sk-live ' | ||
| } | ||
| }]); | ||
| assert.strictEqual(context.showAddModal, false); | ||
| assert.deepStrictEqual(context.newProvider, { name: '', url: '', key: '' }); | ||
| assert.deepStrictEqual(loadAllCalls, ['loadAll']); | ||
| assert.deepStrictEqual(messages[0], { | ||
| text: '操作成功', | ||
| type: 'success' | ||
| }); | ||
| }); | ||
|
|
||
| test('updateProvider blocks invalid edit URL and skips api call', async () => { | ||
| const apiCalls = []; | ||
| const { context, messages } = createContext({ | ||
| editingProvider: { | ||
| name: 'alpha', | ||
| url: 'ftp://api.example.com', | ||
| key: '', | ||
| readOnly: false, | ||
| nonEditable: false | ||
| } | ||
| }, async (action, params) => { | ||
| apiCalls.push({ action, params }); | ||
| return { success: true }; | ||
| }); | ||
|
|
||
| assert.strictEqual(context.canSubmitProvider('edit'), false); | ||
| assert.strictEqual(context.providerFieldError('edit', 'url'), 'URL 仅支持 http/https'); | ||
|
|
||
| await context.updateProvider(); | ||
|
|
||
| assert.deepStrictEqual(apiCalls, []); | ||
| assert.deepStrictEqual(messages[0], { | ||
| text: 'URL 仅支持 http/https', | ||
| type: 'error' | ||
| }); | ||
| }); | ||
|
|
||
| test('provider validation rejects reserved proxy name on add', () => { | ||
| const { context } = createContext({ | ||
| newProvider: { | ||
| name: 'codexmate-proxy', | ||
| url: 'https://api.example.com/v1', | ||
| key: '' | ||
| } | ||
| }); | ||
|
|
||
| assert.strictEqual(context.providerFieldError('add', 'name'), 'codexmate-proxy 为保留名称,不可手动添加'); | ||
| assert.strictEqual(context.canSubmitProvider('add'), false); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.