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

mendersoftware / gui / 1213056175

14 Mar 2024 09:12AM UTC coverage: 83.598% (-16.4%) from 99.964%
1213056175

Pull #4355

gitlab-ci

mineralsfree
fix: Change minimal increment to 1 day, previous units updated automatically

Ticket: MEN-6831
Changelog: None

Signed-off-by: Mikita Pilinka <mikita.pilinka@northern.tech>
Pull Request #4355: MEN-6831: Change minimal increment to 1 day, previous units updated automatically

4439 of 6330 branches covered (70.13%)

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

1633 existing lines in 162 files now uncovered.

8410 of 10060 relevant lines covered (83.6%)

140.64 hits per line

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

79.49
/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 { useradmApiUrl } from '../../../constants/userConstants';
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 => ({
6✔
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
const defaultDetails = [
6✔
59
  { key: 'entityID', label: 'Entity ID', getValue: id => `${window.location.origin}${useradmApiUrl}/sso/sp/metadata/${id}` },
3✔
60
  { key: 'acs', label: 'ACS URL', getValue: id => `${window.location.origin}${useradmApiUrl}/auth/sso/${id}/acs` },
3✔
61
  { key: 'startURL', label: 'Start URL', getValue: id => `${window.location.origin}${useradmApiUrl}/auth/sso/${id}/login` }
3✔
62
];
63

64
export const SSOConfig = ({ ssoItem, config, onCancel, onSave, setSnackbar, token }) => {
6✔
65
  const [configDetails, setConfigDetails] = useState([]);
13✔
66
  const [fileContent, setFileContentState] = useState('');
13✔
67
  const [hasSSOConfig, setHasSSOConfig] = useState(false);
13✔
68
  const [isEditing, setIsEditing] = useState(false);
13✔
69

70
  const { id, ...content } = config || {};
13✔
71
  const configContent = content.config || '';
13✔
72

73
  // file content should be text, otherwise editor will fail
74
  const setFileContent = content => setFileContentState(typeof content === 'object' ? JSON.stringify(content) : content);
13✔
75

76
  const { classes } = useStyles();
13✔
77

78
  useEffect(() => {
13✔
79
    setHasSSOConfig(!!config);
4✔
80
    setFileContent(configContent);
4✔
81
    if (config?.config) {
4✔
82
      setConfigDetails(defaultDetails.map(item => ({ ...item, value: item.getValue(config.id) })));
9✔
83
    }
84
  }, [config, configContent]);
85

86
  const onCancelSSOSettings = () => {
13✔
UNCOV
87
    setHasSSOConfig(!!config);
×
UNCOV
88
    setFileContent(configContent);
×
UNCOV
89
    setIsEditing(false);
×
UNCOV
90
    onCancel();
×
91
  };
92

93
  const onSaveSSOSettings = () => {
13✔
UNCOV
94
    onSave(id, fileContent);
×
UNCOV
95
    setIsEditing(false);
×
96
  };
97

98
  const onDrop = acceptedFiles => {
13✔
99
    let reader = new FileReader();
1✔
100
    reader.fileName = acceptedFiles[0].name;
1✔
101
    reader.onerror = error => console.log('Error: ', error);
1✔
102
    reader.onload = () => {
1✔
UNCOV
103
      setIsEditing(true);
×
UNCOV
104
      setFileContent(reader.result);
×
105
    };
106
    reader.readAsBinaryString(acceptedFiles[0]);
1✔
107
  };
108

109
  const onOpenEditorClick = () => setIsEditing(toggle);
13✔
110

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

178
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