Skip to content

Commit

Permalink
fix: ldap地址格式校验优化 #436
Browse files Browse the repository at this point in the history
  • Loading branch information
v_yutyi authored and EmilyMei committed May 26, 2022
1 parent b026421 commit a049e80
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/pages/src/components/catalog/operation/CommonInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,9 @@ export default {
const url = value.split('://')[0];
this.$emit('updateUrl', url);
// IP | IP + 端口号
const ipReg = new RegExp(/^ldap(s)?:\/\/(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5]):([0-9]|[1-9]\d{1,3})$/);
const ipReg = new RegExp(/^(ldap(s)?:\/\/)?(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])(:([0-9]|[1-9]\d{1,3}))?$/);
// 域名 | 域名 + 端口号
const reg = new RegExp(/^ldap(s)?:\/\/(([a-zA-Z0-9]([-a-zA-Z0-9])*){1,62}\.)+[a-zA-Z]{2,62}(:([0-9]|[1-9]\d{1,3}))?$/);
const reg = new RegExp(/^(ldap(s)?:\/\/)?(([a-zA-Z0-9]([-a-zA-Z0-9])*){1,62}\.)+[a-zA-Z]{2,62}(:([0-9]|[1-9]\d{1,3}))?$/);
this.regError = reg.test(value) || ipReg.test(value);
if (this.regError === false) {
this.$emit('hasError');
Expand Down
14 changes: 11 additions & 3 deletions src/pages/src/components/catalog/operation/SetConnection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
:input-bus="inputBus"
:title="$t('连接地址')"
:is-need="true"
:placeholder="`${$t('例如')}:ldap://127.0.0.1:389`"
:placeholder="`${$t('例如')}:ldap://127.0.0.1:389 ${$t('或')} ldaps://127.0.0.1:636`"
@hasError="handleHasError"
@updateUrl="updateUrl" />

Expand All @@ -45,7 +45,7 @@
@toggle="toggleSelect">
<bk-option v-for="option in sslEncryptionChoices" :key="option" :id="option" :name="option"></bk-option>
</bk-select>
<p v-show="sslError" class="error-text">{{$t('请选择正确的加密方式')}}</p>
<p v-show="sslError" class="error-text">{{sslErrorText}}</p>
</div>

<!-- 超时设置 -->
Expand Down Expand Up @@ -163,6 +163,7 @@ export default {
hasError: false,
inputBus: new Vue(),
sslError: false,
sslErrorText: '',
};
},
computed: {
Expand Down Expand Up @@ -213,8 +214,15 @@ export default {
|| (val === 'ldap' && this.defaultConnection.ssl_encryption === 'SSL')) {
this.sslError = true;
this.hasError = true;
this.sslErrorText = this.$t('请选择正确的加密方式,ldap://必须选择“无”, ldaps://必须选择“SSL”');
} else {
this.sslError = false;
if (val !== 'ldaps' && val !== 'ldap' && this.defaultConnection.ssl_encryption === 'SSL') {
this.sslError = true;
this.hasError = true;
this.sslErrorText = this.$t('加密方式不合法');
} else {
this.sslError = false;
}
}
},
toggleSelect() {
Expand Down
4 changes: 3 additions & 1 deletion src/pages/src/language/lang/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,5 +413,7 @@ export default {
组长: 'group leader',
请输入合法的ldap地址: 'Please enter a valid LDAP address',
例如: 'For example',
请选择正确的加密方式: 'Select the correct encryption mode',
'请选择正确的加密方式,ldap://必须选择“无”, ldaps://必须选择“SSL”': 'Please select the correct encryption mode, ldap:// must be set to None, LDaps :// must be set to SSL',
: 'or',
加密方式不合法: 'The encryption method is invalid',
};
4 changes: 3 additions & 1 deletion src/pages/src/language/lang/zh.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,5 +412,7 @@ export default {
组长: '组长',
请输入合法的ldap地址: '请输入合法的ldap地址',
例如: '例如',
请选择正确的加密方式: '请选择正确的加密方式',
'请选择正确的加密方式,ldap://必须选择“无”, ldaps://必须选择“SSL”': '请选择正确的加密方式,ldap://必须选择“无”, ldaps://必须选择“SSL”',
: '或',
加密方式不合法: '加密方式不合法',
};

0 comments on commit a049e80

Please sign in to comment.