|
1 | 1 | import { describe, expect, it } from 'vitest'; |
2 | 2 | import createHandler from '@/pages/api/support/mcp/create'; |
| 3 | +import deleteHandler from '@/pages/api/support/mcp/delete'; |
3 | 4 | import listHandler from '@/pages/api/support/mcp/list'; |
| 5 | +import updateHandler from '@/pages/api/support/mcp/update'; |
4 | 6 | import { AppTypeEnum } from '@fastgpt/global/core/app/constants'; |
5 | 7 | import { TeamApikeyCreatePermissionVal } from '@fastgpt/global/support/permission/user/constant'; |
6 | 8 | import { MongoApp } from '@fastgpt/service/core/app/schema'; |
@@ -108,4 +110,131 @@ describe('support/mcp publish management', () => { |
108 | 110 | expect(result.code).toBe(500); |
109 | 111 | expect(await MongoMcpKey.findOne({ name: 'member proxy mcp' })).toBeNull(); |
110 | 112 | }); |
| 113 | + |
| 114 | + it('allows the owner to enable authProxy on their MCP publication', async () => { |
| 115 | + const { owner } = await getFakeUsers(1); |
| 116 | + const app = await MongoApp.create({ |
| 117 | + teamId: owner.teamId, |
| 118 | + tmbId: owner.tmbId, |
| 119 | + name: 'owner update app', |
| 120 | + type: AppTypeEnum.simple |
| 121 | + }); |
| 122 | + const mcp = await MongoMcpKey.create({ |
| 123 | + teamId: owner.teamId, |
| 124 | + tmbId: owner.tmbId, |
| 125 | + name: 'owner update mcp', |
| 126 | + apps: [] |
| 127 | + }); |
| 128 | + |
| 129 | + const result = await Call(updateHandler, { |
| 130 | + auth: owner, |
| 131 | + body: { |
| 132 | + id: String(mcp._id), |
| 133 | + authProxy: true, |
| 134 | + apps: [ |
| 135 | + { |
| 136 | + appId: String(app._id), |
| 137 | + appName: app.name, |
| 138 | + toolName: 'owner_update_tool', |
| 139 | + description: 'Owner update tool' |
| 140 | + } |
| 141 | + ] |
| 142 | + } |
| 143 | + }); |
| 144 | + |
| 145 | + expect(result.code).toBe(200); |
| 146 | + expect((await MongoMcpKey.findById(mcp._id).lean())?.authProxy).toBe(true); |
| 147 | + }); |
| 148 | + |
| 149 | + it('rejects enabling authProxy when a non-owner updates their MCP publication', async () => { |
| 150 | + const { members } = await getFakeUsers(1); |
| 151 | + const [member] = members; |
| 152 | + const app = await MongoApp.create({ |
| 153 | + teamId: member.teamId, |
| 154 | + tmbId: member.tmbId, |
| 155 | + name: 'member update app', |
| 156 | + type: AppTypeEnum.simple |
| 157 | + }); |
| 158 | + const mcp = await MongoMcpKey.create({ |
| 159 | + teamId: member.teamId, |
| 160 | + tmbId: member.tmbId, |
| 161 | + name: 'member update mcp', |
| 162 | + apps: [] |
| 163 | + }); |
| 164 | + |
| 165 | + const result = await Call(updateHandler, { |
| 166 | + auth: member, |
| 167 | + body: { |
| 168 | + id: String(mcp._id), |
| 169 | + authProxy: true, |
| 170 | + apps: [ |
| 171 | + { |
| 172 | + appId: String(app._id), |
| 173 | + appName: app.name, |
| 174 | + toolName: 'member_update_tool', |
| 175 | + description: 'Member update tool' |
| 176 | + } |
| 177 | + ] |
| 178 | + } |
| 179 | + }); |
| 180 | + |
| 181 | + expect(result.code).toBe(500); |
| 182 | + expect((await MongoMcpKey.findById(mcp._id).lean())?.authProxy).toBe(false); |
| 183 | + }); |
| 184 | + |
| 185 | + it('allows a non-owner to disable an existing authProxy setting', async () => { |
| 186 | + const { members } = await getFakeUsers(1); |
| 187 | + const [member] = members; |
| 188 | + const app = await MongoApp.create({ |
| 189 | + teamId: member.teamId, |
| 190 | + tmbId: member.tmbId, |
| 191 | + name: 'member disable app', |
| 192 | + type: AppTypeEnum.simple |
| 193 | + }); |
| 194 | + const mcp = await MongoMcpKey.create({ |
| 195 | + teamId: member.teamId, |
| 196 | + tmbId: member.tmbId, |
| 197 | + name: 'member disable mcp', |
| 198 | + authProxy: true, |
| 199 | + apps: [] |
| 200 | + }); |
| 201 | + |
| 202 | + const result = await Call(updateHandler, { |
| 203 | + auth: member, |
| 204 | + body: { |
| 205 | + id: String(mcp._id), |
| 206 | + authProxy: false, |
| 207 | + apps: [ |
| 208 | + { |
| 209 | + appId: String(app._id), |
| 210 | + appName: app.name, |
| 211 | + toolName: 'member_disable_tool', |
| 212 | + description: 'Member disable tool' |
| 213 | + } |
| 214 | + ] |
| 215 | + } |
| 216 | + }); |
| 217 | + |
| 218 | + expect(result.code).toBe(200); |
| 219 | + expect((await MongoMcpKey.findById(mcp._id).lean())?.authProxy).toBe(false); |
| 220 | + }); |
| 221 | + |
| 222 | + it('does not allow a team owner to delete another member publication', async () => { |
| 223 | + const { owner, members } = await getFakeUsers(1); |
| 224 | + const [member] = members; |
| 225 | + const mcp = await MongoMcpKey.create({ |
| 226 | + teamId: member.teamId, |
| 227 | + tmbId: member.tmbId, |
| 228 | + name: 'member private mcp', |
| 229 | + apps: [] |
| 230 | + }); |
| 231 | + |
| 232 | + const result = await Call(deleteHandler, { |
| 233 | + auth: owner, |
| 234 | + query: { id: String(mcp._id) } |
| 235 | + }); |
| 236 | + |
| 237 | + expect(result.code).toBe(500); |
| 238 | + expect(await MongoMcpKey.findById(mcp._id)).not.toBeNull(); |
| 239 | + }); |
111 | 240 | }); |
0 commit comments