Skip to content

Commit 4ccd949

Browse files
authored
fix(#4189): add content type validation for mappings component (#4197)
1 parent cb7f98e commit 4ccd949

2 files changed

Lines changed: 45 additions & 5 deletions

File tree

spring-boot-admin-server-ui/src/main/frontend/views/instances/mappings/index.spec.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { screen, waitFor } from '@testing-library/vue';
2+
import { shallowMount } from '@vue/test-utils';
23
import { describe, expect, it, vi } from 'vitest';
34

45
import Mappings from './index.vue';
@@ -77,6 +78,39 @@ describe('Mappings', () => {
7778
expect(element).toBeVisible();
7879
});
7980

81+
it.each`
82+
contentType
83+
${'application/vnd.spring-boot.actuator.v2+json'}
84+
${'application/vnd.spring-boot.actuator.v3+json'}
85+
${'application/vnd.spring-boot.actuator.v2+json;charset=UTF-8'}
86+
${'application/vnd.spring-boot.actuator.v3+json;charset=UTF-8'}
87+
`('should accept allowed content type headers', ({ contentType }) => {
88+
const wrapper = shallowMount(Mappings, {
89+
props: {
90+
instance: createInstanceWithMappingsData(mappings),
91+
},
92+
});
93+
94+
expect(wrapper.vm.isSupportedContextType(contentType)).toBe(true);
95+
});
96+
97+
it.each`
98+
contentType
99+
${'application/vnd.spring-boot.actuator.v+json'}
100+
${'application/vnd.spring-boot.actuator.v34+json'}
101+
${'invalid'}
102+
${null}
103+
${undefined}
104+
`('should reject content type headers', ({ contentType }) => {
105+
const wrapper = shallowMount(Mappings, {
106+
props: {
107+
instance: createInstanceWithMappingsData(mappings),
108+
},
109+
});
110+
111+
expect(wrapper.vm.isSupportedContextType(contentType)).toBe(false);
112+
});
113+
80114
// Helpers
81115
function renderWithInstance(data) {
82116
render(Mappings, {

spring-boot-admin-server-ui/src/main/frontend/views/instances/mappings/index.vue

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,21 @@ export default {
9898
hasServletFilters(context) {
9999
return context?.mappings?.servletFilters !== undefined;
100100
},
101+
isSupportedContextType(contentType) {
102+
const supportedContentTypes = [
103+
'application/vnd.spring-boot.actuator.v3+json',
104+
'application/vnd.spring-boot.actuator.v2+json',
105+
];
106+
107+
return !!supportedContentTypes.find((supportedContentType) =>
108+
(contentType || '').includes(supportedContentType),
109+
);
110+
},
101111
async fetchMappings() {
102112
this.error = null;
103113
try {
104114
const res = await this.instance.fetchMappings();
105-
const supportedContentTypes = [
106-
'application/vnd.spring-boot.actuator.v3+json',
107-
'application/vnd.spring-boot.actuator.v2+json',
108-
];
109-
if (supportedContentTypes.includes(res.headers['content-type'])) {
115+
if (this.isSupportedContextType(res.headers['content-type'])) {
110116
this.contexts = res.data.contexts;
111117
} else {
112118
this.isOldMetrics = true;

0 commit comments

Comments
 (0)