• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

geosolutions-it / MapStore2 / 19710972030

26 Nov 2025 03:38PM UTC coverage: 76.665% (-0.3%) from 76.929%
19710972030

Pull #11119

github

web-flow
Fix maven publish (#11739)
Pull Request #11119: Layer Selection Plugin on ArcGIS, WFS & WMS layers

32272 of 50209 branches covered (64.28%)

3 of 3 new or added lines in 2 files covered. (100.0%)

3018 existing lines in 249 files now uncovered.

40157 of 52380 relevant lines covered (76.66%)

37.9 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

57.58
/web/client/components/misc/SecureImage.jsx
1
/**
2
 * Copyright 2024, GeoSolutions Sas.
3
 * All rights reserved.
4
 *
5
 * This source code is licensed under the BSD-style license found in the
6
 * LICENSE file in the root directory of this source tree.
7
 */
8

9
import React, { useEffect, useState } from 'react';
10
import axios from 'axios';
11

12
import { getAuthKeyParameter, getAuthenticationMethod, getAuthorizationBasic, getToken } from '../../utils/SecurityUtils';
13
import { updateUrlParams } from '../../utils/URLUtils';
14

15

16
const SecureImage = ({
1✔
17
    alt,
18
    src,
19
    ...props
20
}) => {
21
    const [imageSrc, setImageSrc] = useState('');
74✔
22

23
    // Function to validate the image once it loads
24
    const validateImg = (imgElement) => {
74✔
25
        // Implement your validation logic here
26
        // For example, check image dimensions, aspect ratio, etc.
27
        if (imgElement.naturalWidth === 0 || imgElement.naturalHeight === 0) {
×
28
            console.error('Image validation failed: Image is not valid.');
×
29
        }
30
    };
31
    useEffect(() => {
74✔
32
        const authMethod = getAuthenticationMethod(src);
36✔
33

34
        if (authMethod === "bearer") {
36!
UNCOV
35
            axios.get(src, {
×
36
                responseType: 'blob'
37
            })
38
                .then((response) => {
UNCOV
39
                    const imageUrl = URL.createObjectURL(response.data);
×
40
                    setImageSrc(imageUrl);
×
41
                })
42
                .catch((error) => {
UNCOV
43
                    console.error('Error fetching image:', error);
×
44
                });
45
        } else if (authMethod === "authkey") {
36✔
46
            const authParam = getAuthKeyParameter(src);
3✔
47
            const token = getToken();
3✔
48
            if (authParam && token) {
3!
UNCOV
49
                const newSrc = updateUrlParams(src, {[authParam]: token});
×
50
                setImageSrc(newSrc);
×
51
            } else {
52
                setImageSrc(src);
3✔
53
            }
54

55
        } else if (props?.layer?.security?.sourceId) {
33!
UNCOV
56
            const headers = getAuthorizationBasic(props?.layer?.security?.sourceId);
×
UNCOV
57
            axios.get(src, {
×
58
                responseType: 'blob',
59
                headers
60
            })
61
                .then((response) => {
UNCOV
62
                    const imageUrl = URL.createObjectURL(response.data);
×
UNCOV
63
                    setImageSrc(imageUrl);
×
64
                })
65
                .catch((error) => {
UNCOV
66
                    console.error('Error fetching image:', error);
×
67
                });
68
        } else {
69
            setImageSrc(src);
33✔
70
        }
71

72
        // Clean up the URL object when the component unmounts
73
        return () => {
36✔
74
            if (imageSrc) {
36✔
75
                URL.revokeObjectURL(imageSrc);
6✔
76
            }
77
        };
78
    }, [src]);
79

80
    return (
74✔
81
        <img
82
            alt={alt}
83
            onError={(e) => {
84
                if (imageSrc) {
12!
85
                    props.onImgError(e);
12✔
86
                }
87
            }}
UNCOV
88
            onLoad={(e) => validateImg(e.target)}
×
89
            src={imageSrc}
90
            style={props.style}
91
            {...props}
92
        />
93
    );
94
};
95

96
export default SecureImage;
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc