|
1 | 1 | /* Copyright Contributors to the Open Cluster Management project */
|
| 2 | +import { constants } from 'http2' |
2 | 3 | import nock from 'nock'
|
3 | 4 | import { parsePipedJsonBody } from '../../src/lib/body-parser'
|
4 | 5 | import { request } from '../mock-request'
|
5 | 6 |
|
6 | 7 | describe('Virtual Machine actions', function () {
|
| 8 | + afterEach(() => { |
| 9 | + nock.cleanAll() |
| 10 | + }) |
| 11 | + |
7 | 12 | it('should successfully call start action', async function () {
|
8 | 13 | nock(process.env.CLUSTER_API_URL).get('/apis').reply(200)
|
9 | 14 | nock(process.env.CLUSTER_API_URL)
|
@@ -191,4 +196,76 @@ describe('Virtual Machine actions', function () {
|
191 | 196 | })
|
192 | 197 | expect(res.statusCode).toEqual(500)
|
193 | 198 | })
|
| 199 | + |
| 200 | + it('should fail with 502 - content type text/plain error', async function () { |
| 201 | + nock(process.env.CLUSTER_API_URL).get('/apis').reply(200) |
| 202 | + nock(process.env.CLUSTER_API_URL) |
| 203 | + .post( |
| 204 | + '/apis/authorization.k8s.io/v1/selfsubjectaccessreviews', |
| 205 | + '{"apiVersion":"authorization.k8s.io/v1","kind":"SelfSubjectAccessReview","metadata":{},"spec":{"resourceAttributes":{"group":"action.open-cluster-management.io","namespace":"testCluster","resource":"managedclusteractions","verb":"create"}}}' |
| 206 | + ) |
| 207 | + .reply(200, { |
| 208 | + status: { |
| 209 | + allowed: true, |
| 210 | + }, |
| 211 | + }) |
| 212 | + nock(process.env.CLUSTER_API_URL) |
| 213 | + .get('/api/v1/namespaces/testCluster/secrets') |
| 214 | + .reply(200, { |
| 215 | + statusCode: 200, |
| 216 | + apiVersion: 'v1', |
| 217 | + kind: 'SecretList', |
| 218 | + items: [ |
| 219 | + { |
| 220 | + kind: 'Secret', |
| 221 | + apiVersion: 'v1', |
| 222 | + metadata: { |
| 223 | + name: 'vm-actor', |
| 224 | + namespace: 'testCluster', |
| 225 | + }, |
| 226 | + data: { |
| 227 | + // test-vm-token |
| 228 | + token: 'dGVzdC12bS10b2tlbg==', // notsecret |
| 229 | + }, |
| 230 | + type: 'Opaque', |
| 231 | + }, |
| 232 | + ], |
| 233 | + }) |
| 234 | + nock(process.env.CLUSTER_API_URL) |
| 235 | + .get('/apis/route.openshift.io/v1/namespaces/multicluster-engine/routes/cluster-proxy-addon-user') |
| 236 | + .reply(200, { |
| 237 | + kind: 'Route', |
| 238 | + apiVersion: 'route.openshift.io/v1', |
| 239 | + metadata: { |
| 240 | + name: 'cluster-proxy-addon-user', |
| 241 | + namespace: 'multicluster-engine', |
| 242 | + }, |
| 243 | + spec: { |
| 244 | + host: 'testCluster.red-chesterfield.com', |
| 245 | + to: { |
| 246 | + kind: 'Service', |
| 247 | + name: 'cluster-proxy-addon-user', |
| 248 | + weight: 100, |
| 249 | + }, |
| 250 | + port: { |
| 251 | + targetPort: 'user-port', |
| 252 | + }, |
| 253 | + tls: { |
| 254 | + termination: 'reencrypt', |
| 255 | + insecureEdgeTerminationPolicy: 'Redirect', |
| 256 | + }, |
| 257 | + wildcardPolicy: 'None', |
| 258 | + }, |
| 259 | + }) |
| 260 | + nock('https://testcluster.red-chesterfield.com') |
| 261 | + .put('/testCluster/apis/subresources.kubevirt.io/v1/namespaces/vmNamespace/virtualmachines/vmName/start') |
| 262 | + .reply(502, 'plain text error', { [constants.HTTP2_HEADER_CONTENT_TYPE]: ['text/plain'] }) |
| 263 | + const res = await request('PUT', '/virtualmachines/start', { |
| 264 | + managedCluster: 'testCluster', |
| 265 | + vmName: 'vmName', |
| 266 | + vmNamespace: 'vmNamespace', |
| 267 | + }) |
| 268 | + expect(res.statusCode).toEqual(502) |
| 269 | + expect(await parsePipedJsonBody(res)).toEqual('plain text error') |
| 270 | + }) |
194 | 271 | })
|
0 commit comments