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

mendersoftware / gui / 901187442

pending completion
901187442

Pull #3795

gitlab-ci

mzedel
feat: increased chances of adopting our intended navigation patterns instead of unsupported browser navigation

Ticket: None
Changelog: None
Signed-off-by: Manuel Zedel <manuel.zedel@northern.tech>
Pull Request #3795: feat: increased chances of adopting our intended navigation patterns instead of unsupported browser navigation

4389 of 6365 branches covered (68.96%)

5 of 5 new or added lines in 1 file covered. (100.0%)

1729 existing lines in 165 files now uncovered.

8274 of 10019 relevant lines covered (82.58%)

144.86 hits per line

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

96.49
/src/js/components/settings/organization/samlconfig.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 InfoHint from '../../common/info-hint';
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
    ['&.has-sso']: {
52
      gridTemplateColumns: `${maxWidth - 45}px 1fr`
53
    }
54
  }
55
}));
56

57
const defaultDetails = [
7✔
58
  { key: 'entityID', label: 'Entity ID', getValue: id => `${window.location.origin}${useradmApiUrl}/sso/sp/metadata/${id}` },
1✔
59
  { key: 'acs', label: 'ACS URL', getValue: id => `${window.location.origin}${useradmApiUrl}/auth/sso/${id}/acs` },
1✔
60
  { key: 'startURL', label: 'Start URL', getValue: id => `${window.location.origin}${useradmApiUrl}/auth/sso/${id}/login` }
1✔
61
];
62

63
export const SAMLConfig = ({ configs, onCancel, onSave, setSnackbar }) => {
7✔
64
  const [configDetails, setConfigDetails] = useState([]);
8✔
65
  const [fileContent, setFileContent] = useState('');
8✔
66
  const [hasSSOConfig, setHasSSOConfig] = useState(false);
8✔
67
  const [isEditing, setIsEditing] = useState(false);
8✔
68

69
  const config = configs.length ? configs[0] : undefined;
8✔
70
  const { id, ...content } = config || {};
8✔
71
  const configContent = content.config || '';
8✔
72

73
  const { classes } = useStyles();
8✔
74

75
  useEffect(() => {
8✔
76
    setHasSSOConfig(!!config);
3✔
77
    setFileContent(configContent);
3✔
78
    if (config?.config) {
3✔
79
      setConfigDetails(defaultDetails.map(item => ({ ...item, value: item.getValue(config.id) })));
3✔
80
    }
81
  }, [config, configContent]);
82

83
  const onCancelSSOSettings = () => {
8✔
84
    setHasSSOConfig(!!config);
1✔
85
    setFileContent(configContent);
1✔
86
    setIsEditing(false);
1✔
87
    onCancel();
1✔
88
  };
89

90
  const onSaveSSOSettings = () => {
8✔
UNCOV
91
    onSave(id, fileContent);
×
UNCOV
92
    setIsEditing(false);
×
93
  };
94

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

106
  const onOpenEditorClick = () => setIsEditing(toggle);
8✔
107

108
  return (
8✔
109
    <>
110
      <div className={`flexbox center-aligned ${classes.wrapper} ${hasSSOConfig ? 'has-sso' : ''}`}>
8✔
111
        {hasSSOConfig ? (
8✔
112
          <a onClick={onOpenEditorClick}>View metadata in the text editor</a>
113
        ) : (
114
          <>
115
            <Dropzone multiple={false} onDrop={onDrop}>
116
              {({ getRootProps, getInputProps }) => (
117
                <div {...getRootProps()} className="dropzone onboard dashboard-placeholder flexbox centered">
14✔
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 ? (
17✔
131
            <Button onClick={onOpenEditorClick}>Edit</Button>
132
          ) : (
133
            <>
134
              <Button onClick={onCancelSSOSettings}>Cancel</Button>
135
              <Button className={classes.tinyMargin} onClick={onSaveSSOSettings} disabled={!fileContent} variant="contained">
136
                Save
137
              </Button>
138
            </>
139
          )}
140
        </div>
141
      </div>
142
      {hasSSOConfig ? (
8✔
143
        <div className="flexbox column margin-top">
144
          {configDetails.map(item => (
145
            <ExpandableAttribute
3✔
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
        <InfoHint content="Submit the metadata document from your Identity Provider" />
159
      )}
160
      <SSOEditor
161
        open={isEditing}
162
        config={configContent}
163
        fileContent={fileContent}
164
        hasSSOConfig={hasSSOConfig}
165
        onCancel={onCancelSSOSettings}
166
        onClose={onOpenEditorClick}
167
        onSave={onSaveSSOSettings}
168
        setFileContent={setFileContent}
169
      />
170
    </>
171
  );
172
};
173

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