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

mendersoftware / gui / 1350829378

27 Jun 2024 01:46PM UTC coverage: 83.494% (-16.5%) from 99.965%
1350829378

Pull #4465

gitlab-ci

mzedel
chore: test fixes

Signed-off-by: Manuel Zedel <manuel.zedel@northern.tech>
Pull Request #4465: MEN-7169 - feat: added multi sorting capabilities to devices view

4506 of 6430 branches covered (70.08%)

81 of 100 new or added lines in 14 files covered. (81.0%)

1661 existing lines in 163 files now uncovered.

8574 of 10269 relevant lines covered (83.49%)

160.6 hits per line

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

63.89
/src/js/components/settings/organization/ssoconfig.js
1
// Copyright 2022 Northern.tech AS
2
//
3
//    Licensed under the Apache License, Version 2.0 (the "License");
4
//    you may not use this file except in compliance with the License.
5
//    You may obtain a copy of the License at
6
//
7
//        http://www.apache.org/licenses/LICENSE-2.0
8
//
9
//    Unless required by applicable law or agreed to in writing, software
10
//    distributed under the License is distributed on an "AS IS" BASIS,
11
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
//    See the License for the specific language governing permissions and
13
//    limitations under the License.
14
import React, { useEffect, useState } from 'react';
15
import Dropzone from 'react-dropzone';
16

17
// material ui
18
import { CloudUpload } from '@mui/icons-material';
19
import { Button } from '@mui/material';
20
import { listItemTextClasses } from '@mui/material/ListItemText';
21
import { makeStyles } from 'tss-react/mui';
22

23
import { SSO_TYPES, XML_METADATA_FORMAT } from '../../../constants/organizationConstants.js';
24
import { toggle } from '../../../helpers';
25
import ExpandableAttribute from '../../common/expandable-attribute';
26
import { HELPTOOLTIPS, MenderHelpTooltip } from '../../helptips/helptooltips';
27
import { maxWidth } from './organizationsettingsitem';
28
import SSOEditor from './ssoeditor';
29

30
const useStyles = makeStyles()(theme => ({
7✔
31
  configDetail: {
32
    maxWidth,
33
    [`.${listItemTextClasses.primary}`]: {
34
      color: theme.palette.text.disabled,
35
      fontSize: 'smaller'
36
    }
37
  },
38
  uploadIcon: {
39
    marginBottom: theme.spacing(-0.5),
40
    marginRight: theme.spacing()
41
  },
42
  tinyMargin: {
43
    marginLeft: theme.spacing(0.5),
44
    marginRight: theme.spacing(0.5)
45
  },
46
  wrapper: {
47
    alignItems: 'start',
48
    columnGap: theme.spacing(2),
49
    display: 'grid',
50
    gridTemplateColumns: `minmax(max-content, ${maxWidth}px) max-content max-content`,
51
    position: 'relative',
52
    ['&.has-sso']: {
53
      gridTemplateColumns: `${maxWidth - 45}px 1fr`
54
    }
55
  }
56
}));
57

58
export const SSOConfig = ({ ssoItem, config, onCancel, onSave, setSnackbar, token }) => {
7✔
59
  const [configDetails, setConfigDetails] = useState([]);
7✔
60
  const [fileContent, setFileContentState] = useState('');
7✔
61
  const [hasSSOConfig, setHasSSOConfig] = useState(false);
7✔
62
  const [isEditing, setIsEditing] = useState(false);
7✔
63
  const { id, type, ...content } = config || {};
7!
64
  const configContent = content.config || '';
7!
65

66
  // file content should be text, otherwise editor will fail
67
  const setFileContent = content => setFileContentState(typeof content === 'object' ? JSON.stringify(content) : content);
7✔
68

69
  const { classes } = useStyles();
7✔
70

71
  useEffect(() => {
7✔
72
    setHasSSOConfig(!!config);
2✔
73
    setFileContent(configContent);
2✔
74
    if (config?.id) {
2!
75
      setConfigDetails(SSO_TYPES[type].configDetails.map(item => ({ ...item, value: item.getValue(config.id) })));
4✔
76
    }
77
  }, [config, configContent, type]);
78

79
  const onCancelSSOSettings = () => {
7✔
UNCOV
80
    setHasSSOConfig(!!config);
×
UNCOV
81
    setFileContent(configContent);
×
UNCOV
82
    setIsEditing(false);
×
UNCOV
83
    onCancel();
×
84
  };
85

86
  const onSaveSSOSettings = () => {
7✔
UNCOV
87
    onSave(id, fileContent);
×
UNCOV
88
    setIsEditing(false);
×
89
  };
90

91
  const onDrop = acceptedFiles => {
7✔
UNCOV
92
    let reader = new FileReader();
×
UNCOV
93
    reader.fileName = acceptedFiles[0].name;
×
UNCOV
94
    reader.onerror = error => console.log('Error: ', error);
×
UNCOV
95
    reader.onload = () => {
×
UNCOV
96
      setIsEditing(true);
×
UNCOV
97
      setFileContent(reader.result);
×
98
    };
UNCOV
99
    reader.readAsBinaryString(acceptedFiles[0]);
×
100
  };
101

102
  const onOpenEditorClick = () => setIsEditing(toggle);
7✔
103

104
  // disable save button if there is no metadata content and metadata format is not xml that means SAML. As we allow to save empty SAML SSO config
105
  const saveButtonDisabled = !fileContent && ssoItem.metadataFormat !== XML_METADATA_FORMAT;
7✔
106

107
  return (
7✔
108
    <>
109
      <div className={`flexbox center-aligned ${classes.wrapper} ${hasSSOConfig ? 'has-sso' : ''}`}>
7✔
110
        {hasSSOConfig ? (
7✔
111
          <a onClick={onOpenEditorClick}>View metadata in the text editor</a>
112
        ) : (
113
          <>
114
            <MenderHelpTooltip id={HELPTOOLTIPS.ssoMetadata.id} style={{ position: 'absolute', left: -35 }} placement="left" />
115
            <Dropzone multiple={false} onDrop={onDrop}>
116
              {({ getRootProps, getInputProps }) => (
117
                <div {...getRootProps()} className="dropzone onboard dashboard-placeholder flexbox centered">
2✔
118
                  <input {...getInputProps()} />
119
                  <CloudUpload className={classes.uploadIcon} fontSize="small" /> Drag here or <a className={classes.tinyMargin}>browse</a> to upload a metadata
120
                  document
121
                </div>
122
              )}
123
            </Dropzone>
124
            <div>
125
              or <a onClick={onOpenEditorClick}>input with the text editor</a>
126
            </div>
127
          </>
128
        )}
129
        <div className="flexbox">
130
          {hasSSOConfig && !isEditing ? (
19✔
131
            <Button onClick={onOpenEditorClick}>Edit</Button>
132
          ) : (
133
            <>
134
              <Button onClick={onCancelSSOSettings}>Cancel</Button>
135
              <Button className={classes.tinyMargin} onClick={onSaveSSOSettings} disabled={saveButtonDisabled} variant="contained">
136
                Save
137
              </Button>
138
            </>
139
          )}
140
        </div>
141
      </div>
142
      {hasSSOConfig && (
12✔
143
        <div className="flexbox column margin-top">
144
          {configDetails.map(item => (
145
            <ExpandableAttribute
7✔
146
              className={classes.configDetail}
147
              copyToClipboard
148
              key={item.key}
149
              primary={item.label}
150
              secondary={item.value}
151
              setSnackbar={setSnackbar}
152
              disableGutters
153
              dividerDisabled
154
            />
155
          ))}
156
        </div>
157
      )}
158
      <SSOEditor
159
        open={isEditing}
160
        ssoItem={ssoItem}
161
        config={configContent}
162
        fileContent={fileContent}
163
        hasSSOConfig={hasSSOConfig}
164
        onCancel={onCancelSSOSettings}
165
        onClose={onOpenEditorClick}
166
        onSave={onSaveSSOSettings}
167
        setFileContent={setFileContent}
168
        token={token}
169
      />
170
    </>
171
  );
172
};
173

174
export default SSOConfig;
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