Skip to content

Commit

Permalink
Merge pull request #571 from jeremmfr/bugfix-2.3.0
Browse files Browse the repository at this point in the history
Release v2.3.1
  • Loading branch information
jeremmfr authored Nov 10, 2023
2 parents 440658b + f592395 commit aafa5f9
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 15 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
<!-- markdownlint-disable-file MD013 MD041 -->
# changelog

## v2.3.1 (November 10, 2023)

BUG FIXES:

* **resource/junos_system**: fix value validator (also accept `@`, `.`) on `ciphers`, `hostkey_algorithm`, `key_exchange` and `macs` attributes in `ssh` block in `services` block (Fix [#570](https://github.com/jeremmfr/terraform-provider-junos/issues/570))

## v2.3.0 (November 08, 2023)

ENHANCEMENTS:
Expand Down
20 changes: 10 additions & 10 deletions internal/providerfwk/resource_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -1037,7 +1037,7 @@ func (rsc *system) Schema(
setvalidator.SizeAtLeast(1),
setvalidator.ValueStringsAre(
stringvalidator.LengthAtLeast(1),
tfvalidator.StringFormat(tfvalidator.DefaultFormat),
tfvalidator.StringFormat(tfvalidator.AlgorithmFormat),
),
},
},
Expand Down Expand Up @@ -1077,7 +1077,7 @@ func (rsc *system) Schema(
setvalidator.SizeAtLeast(1),
setvalidator.ValueStringsAre(
stringvalidator.LengthAtLeast(1),
tfvalidator.StringFormat(tfvalidator.DefaultFormat),
tfvalidator.StringFormat(tfvalidator.AlgorithmFormat),
),
},
},
Expand All @@ -1089,7 +1089,7 @@ func (rsc *system) Schema(
setvalidator.SizeAtLeast(1),
setvalidator.ValueStringsAre(
stringvalidator.LengthAtLeast(1),
tfvalidator.StringFormat(tfvalidator.DefaultFormat),
tfvalidator.StringFormat(tfvalidator.AlgorithmFormat),
),
},
},
Expand All @@ -1108,7 +1108,7 @@ func (rsc *system) Schema(
setvalidator.SizeAtLeast(1),
setvalidator.ValueStringsAre(
stringvalidator.LengthAtLeast(1),
tfvalidator.StringFormat(tfvalidator.DefaultFormat),
tfvalidator.StringFormat(tfvalidator.AlgorithmFormat),
),
},
},
Expand Down Expand Up @@ -3506,16 +3506,16 @@ func (block *systemBlockServices) configSet() (
configSet = append(configSet, setPrefix+"ssh fingerprint-hash "+v)
}
for _, v := range block.SSH.HostkeyAlgorithm {
configSet = append(configSet, setPrefix+"ssh hostkey-algorithm "+v.ValueString())
configSet = append(configSet, setPrefix+"ssh hostkey-algorithm \""+v.ValueString()+"\"")
}
for _, v := range block.SSH.KeyExchange {
configSet = append(configSet, setPrefix+"ssh key-exchange "+v.ValueString())
configSet = append(configSet, setPrefix+"ssh key-exchange \""+v.ValueString()+"\"")
}
if block.SSH.LogKeyChanges.ValueBool() {
configSet = append(configSet, setPrefix+"ssh log-key-changes")
}
for _, v := range block.SSH.Macs {
configSet = append(configSet, setPrefix+"ssh macs "+v.ValueString())
configSet = append(configSet, setPrefix+"ssh macs \""+v.ValueString()+"\"")
}
if !block.SSH.MaxPreAuthenticationPackets.IsNull() {
configSet = append(configSet, setPrefix+"ssh max-pre-authentication-packets "+
Expand Down Expand Up @@ -4354,13 +4354,13 @@ func (block *systemBlockServicesBlockSSH) read(itemTrim string) (err error) {
case balt.CutPrefixInString(&itemTrim, "fingerprint-hash "):
block.FingerprintHash = types.StringValue(itemTrim)
case balt.CutPrefixInString(&itemTrim, "hostkey-algorithm "):
block.HostkeyAlgorithm = append(block.HostkeyAlgorithm, types.StringValue(itemTrim))
block.HostkeyAlgorithm = append(block.HostkeyAlgorithm, types.StringValue(strings.Trim(itemTrim, "\"")))
case balt.CutPrefixInString(&itemTrim, "key-exchange "):
block.KeyExchange = append(block.KeyExchange, types.StringValue(itemTrim))
block.KeyExchange = append(block.KeyExchange, types.StringValue(strings.Trim(itemTrim, "\"")))
case itemTrim == "log-key-changes":
block.LogKeyChanges = types.BoolValue(true)
case balt.CutPrefixInString(&itemTrim, "macs "):
block.Macs = append(block.Macs, types.StringValue(itemTrim))
block.Macs = append(block.Macs, types.StringValue(strings.Trim(itemTrim, "\"")))
case balt.CutPrefixInString(&itemTrim, "max-pre-authentication-packets "):
block.MaxPreAuthenticationPackets, err = tfdata.ConvAtoi64Value(itemTrim)
if err != nil {
Expand Down
8 changes: 6 additions & 2 deletions internal/providerfwk/resource_system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,13 @@ func TestAccResourceSystem_basic(t *testing.T) {
resource.TestCheckResourceAttr("junos_system.testacc_system",
"services.ssh.authentication_order.0", "password"),
resource.TestCheckResourceAttr("junos_system.testacc_system",
"services.ssh.ciphers.#", "2"),
"services.ssh.ciphers.#", "3"),
resource.TestCheckTypeSetElemAttr("junos_system.testacc_system",
"services.ssh.ciphers.*", "aes256-ctr"),
resource.TestCheckTypeSetElemAttr("junos_system.testacc_system",
"services.ssh.ciphers.*", "aes256-cbc"),
resource.TestCheckTypeSetElemAttr("junos_system.testacc_system",
"services.ssh.ciphers.*", "[email protected]"),
resource.TestCheckResourceAttr("junos_system.testacc_system",
"services.ssh.client_alive_count_max", "10"),
resource.TestCheckResourceAttr("junos_system.testacc_system",
Expand All @@ -121,9 +123,11 @@ func TestAccResourceSystem_basic(t *testing.T) {
resource.TestCheckTypeSetElemAttr("junos_system.testacc_system",
"services.ssh.key_exchange.*", "ecdh-sha2-nistp256"),
resource.TestCheckResourceAttr("junos_system.testacc_system",
"services.ssh.macs.#", "1"),
"services.ssh.macs.#", "2"),
resource.TestCheckTypeSetElemAttr("junos_system.testacc_system",
"services.ssh.macs.*", "hmac-sha2-256"),
resource.TestCheckTypeSetElemAttr("junos_system.testacc_system",
"services.ssh.macs.*", "[email protected]"),
resource.TestCheckResourceAttr("junos_system.testacc_system",
"services.ssh.max_pre_authentication_packets", "10000"),
resource.TestCheckResourceAttr("junos_system.testacc_system",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,14 @@ resource "junos_system" "testacc_system" {
}
ssh {
authentication_order = ["password"]
ciphers = ["aes256-ctr", "aes256-cbc"]
ciphers = ["aes256-ctr", "aes256-cbc", "[email protected]"]
client_alive_count_max = 10
client_alive_interval = 30
connection_limit = 10
fingerprint_hash = "md5"
hostkey_algorithm = ["no-ssh-dss"]
key_exchange = ["ecdh-sha2-nistp256"]
macs = ["hmac-sha2-256"]
macs = ["hmac-sha2-256", "[email protected]"]
max_pre_authentication_packets = 10000
max_sessions_per_connection = 100
port = 22
Expand Down
11 changes: 10 additions & 1 deletion internal/tfvalidator/string_format.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ const (
InterfaceWithWildcardFormat
HexadecimalFormat
ASPathRegularExpression
AlgorithmFormat
)

func (f stringFormat) invalidRune() func(rune) bool {
switch f {
case DefaultFormat:
return func(r rune) bool {
return (r < 'a' || r > 'z') && (r < 'A' || r > 'Z') && (r < '0' || r > '9') && r != '-' && r != '_'
return (r < 'a' || r > 'z') && (r < 'A' || r > 'Z') && (r < '0' || r > '9') &&
r != '-' && r != '_'
}
case AddressNameFormat:
return func(r rune) bool {
Expand Down Expand Up @@ -58,6 +60,11 @@ func (f stringFormat) invalidRune() func(rune) bool {
r != '+' && r != '?' && r != '{' && r != '}' && r != '.' && r != '[' && r != ']' &&
r != '(' && r != ')' && (r < '0' || r > '9') && r != ' '
}
case AlgorithmFormat:
return func(r rune) bool {
return (r < 'a' || r > 'z') && (r < 'A' || r > 'Z') && (r < '0' || r > '9') &&
r != '-' && r != '_' && r != '@' && r != '.'
}
default:
return func(r rune) bool {
return true
Expand All @@ -81,6 +88,8 @@ func (f stringFormat) String() string {
return "A-F or a-f letters and numbers"
case ASPathRegularExpression:
return "regular expression characters, numbers and spaces"
case AlgorithmFormat:
return "letters, numbers, dashes, underscores, at symbol and dots"
default:
return ""
}
Expand Down
10 changes: 10 additions & 0 deletions internal/tfvalidator/string_format_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,16 @@ func TestStringFormat(t *testing.T) {
format: ASPathRegularExpression,
expectError: true,
},
"AlgorithmFormat_valid": {
val: types.StringValue("[email protected]"),
format: AlgorithmFormat,
expectError: false,
},
"AlgorithmFormat_invalid": {
val: types.StringValue("not [email protected]"),
format: AlgorithmFormat,
expectError: true,
},
}

for name, test := range tests {
Expand Down

0 comments on commit aafa5f9

Please sign in to comment.