Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 42 additions & 2 deletions internal/namespaces/iam/v1alpha1/custom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
iam "github.com/scaleway/scaleway-cli/v2/internal/namespaces/iam/v1alpha1"
"github.com/scaleway/scaleway-cli/v2/internal/testhelpers"
iamsdk "github.com/scaleway/scaleway-sdk-go/api/iam/v1alpha1"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func Test_initWithSSHKeyCommand(t *testing.T) {
Expand Down Expand Up @@ -43,11 +45,11 @@ func Test_initWithSSHKeyCommand(t *testing.T) {
}

func Test_SSHKeyCreateCommand(t *testing.T) {
key := `ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBBieay3nO9wViPkuvFVgGGaA1IRlkFrr946yqvg9LxZIRhsnZ61yLCPmIOhvUAZ/gTxZGmhgtMDxkenSUTsG3F0= foobar@foobar`
key1 := `ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBBieay3nO9wViPkuvFVgGGaA1IRlkFrr946yqvg9LxZIRhsnZ61yLCPmIOhvUAZ/gTxZGmhgtMDxkenSUTsG3F0= foobar@foobar`
t.Run("simple", core.Test(&core.TestConfig{
Commands: iam.GetCommands(),
Args: []string{
"scw", "iam", "ssh-key", "create", "name=foobar", "public-key=" + key,
"scw", "iam", "ssh-key", "create", "name=foobar", "public-key=" + key1,
},
Check: core.TestCheckCombine(
core.TestCheckGolden(),
Expand All @@ -62,6 +64,44 @@ func Test_SSHKeyCreateCommand(t *testing.T) {
})
},
}))

////
// File import will test the @/path/file import functionality
////
key2 := "ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBIHoWVcE8ItB7WPbmanQY/GhMWqU2XKQthfoAv51IE4OAgnnMWo7RHf1grLdiRZ4MxIwW2SaDBGIDminJCw1OMo= foobar@foobar2"
t.Run("file_import", func(t *testing.T) {
f, err := os.CreateTemp(t.TempDir(), "ssh.pub")
require.NoError(t, err)
assert.NotNil(t, f)
defer os.Remove(f.Name()) // clean up

_, err = f.WriteString(key2)
require.NoError(t, err)
t.Logf("public key written on %s (will be deleted at the end of the test)", f.Name())

err = f.Close()
require.NoError(t, err)

testConfig := &core.TestConfig{
Commands: iam.GetCommands(),
Args: []string{
"scw", "iam", "ssh-key", "create", "name=foobar2", "public-key=@" + f.Name(),
},
Check: core.TestCheckCombine(
core.TestCheckGolden(),
core.TestCheckExitCode(0),
),
AfterFunc: func(ctx *core.AfterFuncCtx) error {
api := iamsdk.NewAPI(ctx.Client)
key := testhelpers.Value[*iamsdk.SSHKey](t, ctx.CmdResult)

return api.DeleteSSHKey(&iamsdk.DeleteSSHKeyRequest{
SSHKeyID: key.ID,
})
},
}
core.Test(testConfig)(t)
})
}

func Test_SSHKeyRemoveCommand(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
---
version: 1
interactions:
- request:
body: '{"id":"35d4a543-ba4f-46b8-94a1-3e7d1caeccb9", "name":"foobar2", "public_key":"ecdsa-sha2-nistp256
AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBIHoWVcE8ItB7WPbmanQY/GhMWqU2XKQthfoAv51IE4OAgnnMWo7RHf1grLdiRZ4MxIwW2SaDBGIDminJCw1OMo=",
"fingerprint":"256 MD5:a5:b1:5a:ff:d2:71:ed:53:d7:8c:fb:b0:ec:12:10:de (ecdsa-sha2-nistp256)",
"created_at":"2025-10-21T10:06:35.771313Z", "updated_at":"2025-10-21T10:06:35.771313Z",
"organization_id":"9e9389ca-503a-44c3-bbd5-7a3812303bb0", "project_id":"9e9389ca-503a-44c3-bbd5-7a3812303bb0",
"disabled":false}'
form: {}
headers:
Content-Type:
- application/json
User-Agent:
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.25.0; linux; amd64) cli-e2e-test
url: https://api.scaleway.com/iam/v1alpha1/ssh-keys
method: POST
response:
body: '{"id":"35d4a543-ba4f-46b8-94a1-3e7d1caeccb9", "name":"foobar2", "public_key":"ecdsa-sha2-nistp256
AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBIHoWVcE8ItB7WPbmanQY/GhMWqU2XKQthfoAv51IE4OAgnnMWo7RHf1grLdiRZ4MxIwW2SaDBGIDminJCw1OMo=",
"fingerprint":"256 MD5:a5:b1:5a:ff:d2:71:ed:53:d7:8c:fb:b0:ec:12:10:de (ecdsa-sha2-nistp256)",
"created_at":"2025-10-21T10:06:35.771313Z", "updated_at":"2025-10-21T10:06:35.771313Z",
"organization_id":"9e9389ca-503a-44c3-bbd5-7a3812303bb0", "project_id":"9e9389ca-503a-44c3-bbd5-7a3812303bb0",
"disabled":false}'
headers:
Content-Length:
- "552"
Content-Security-Policy:
- default-src 'none'; frame-ancestors 'none'
Content-Type:
- application/json
Date:
- Tue, 21 Oct 2025 10:06:35 GMT
Server:
- Scaleway API Gateway (fr-par-1;edge02)
Strict-Transport-Security:
- max-age=63072000
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- DENY
X-Request-Id:
- 686dc9c2-3fe0-42ca-92fa-9a3ff0b60e1e
status: 200 OK
code: 200
duration: ""
- request:
body: ""
form: {}
headers:
User-Agent:
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.25.0; linux; amd64) cli-e2e-test
url: https://api.scaleway.com/iam/v1alpha1/ssh-keys/35d4a543-ba4f-46b8-94a1-3e7d1caeccb9
method: DELETE
response:
body: ""
headers:
Content-Security-Policy:
- default-src 'none'; frame-ancestors 'none'
Content-Type:
- application/json
Date:
- Tue, 21 Oct 2025 10:06:35 GMT
Server:
- Scaleway API Gateway (fr-par-1;edge02)
Strict-Transport-Security:
- max-age=63072000
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- DENY
X-Request-Id:
- bc788029-3879-4eff-a462-68b6adbddcb7
status: 204 No Content
code: 204
duration: ""
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟩🟩🟩 STDOUT️ 🟩🟩🟩️
ID 35d4a543-ba4f-46b8-94a1-3e7d1caeccb9
Name foobar2
PublicKey ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBIHoWVcE8ItB7WPbmanQY/GhMWqU2XKQthfoAv51IE4OAgnnMWo7RHf1grLdiRZ4MxIwW2SaDBGIDminJCw1OMo=
Fingerprint 256 MD5:a5:b1:5a:ff:d2:71:ed:53:d7:8c:fb:b0:ec:12:10:de (ecdsa-sha2-nistp256)
CreatedAt few seconds ago
UpdatedAt few seconds ago
OrganizationID 9e9389ca-503a-44c3-bbd5-7a3812303bb0
ProjectID 9e9389ca-503a-44c3-bbd5-7a3812303bb0
Disabled false
🟩🟩🟩 JSON STDOUT 🟩🟩🟩
{
"id": "35d4a543-ba4f-46b8-94a1-3e7d1caeccb9",
"name": "foobar2",
"public_key": "ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBIHoWVcE8ItB7WPbmanQY/GhMWqU2XKQthfoAv51IE4OAgnnMWo7RHf1grLdiRZ4MxIwW2SaDBGIDminJCw1OMo=",
"fingerprint": "256 MD5:a5:b1:5a:ff:d2:71:ed:53:d7:8c:fb:b0:ec:12:10:de (ecdsa-sha2-nistp256)",
"created_at": "1970-01-01T00:00:00.0Z",
"updated_at": "1970-01-01T00:00:00.0Z",
"organization_id": "9e9389ca-503a-44c3-bbd5-7a3812303bb0",
"project_id": "9e9389ca-503a-44c3-bbd5-7a3812303bb0",
"disabled": false
}
Loading