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

geosolutions-it / MapStore2 / 13049117251

30 Jan 2025 09:15AM UTC coverage: 76.848% (-0.3%) from 77.161%
13049117251

Pull #10731

github

web-flow
Merge 999fc935b into fc230b6ff
Pull Request #10731: Fix #10631 New MapStore Home Page

31097 of 48599 branches covered (63.99%)

849 of 1323 new or added lines in 74 files covered. (64.17%)

13 existing lines in 5 files now uncovered.

38630 of 50268 relevant lines covered (76.85%)

34.4 hits per line

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

66.67
/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, 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('');
69✔
22

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

32
    useEffect(() => {
69✔
33
        const authMethod = getAuthenticationMethod(src);
33✔
34

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

56
        } else {
57
            setImageSrc(src);
30✔
58
        }
59

60
        // Clean up the URL object when the component unmounts
61
        return () => {
33✔
62
            if (imageSrc) {
33✔
63
                URL.revokeObjectURL(imageSrc);
5✔
64
            }
65
        };
66
    }, [src]);
67

68
    return (
69✔
69
        <img
70
            alt={alt}
71
            onError={(e) => {
72
                if (imageSrc) {
13!
73
                    props.onImgError(e);
13✔
74
                }
75
            }}
UNCOV
76
            onLoad={(e) => validateImg(e.target)}
×
77
            src={imageSrc}
78
            style={props.style}
79
            {...props}
80
        />
81
    );
82
};
83

84
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

© 2026 Coveralls, Inc