-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from authlete/qa_tooling
Qa tooling
- Loading branch information
Showing
7 changed files
with
744 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
version: 2 | ||
updates: | ||
- package-ecosystem: "github-actions" | ||
directory: "/" | ||
schedule: | ||
interval: "daily" | ||
|
||
- package-ecosystem: "gomod" | ||
directory: "/" | ||
schedule: | ||
interval: "daily" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# This GitHub action runs your tests for each commit push and/or PR. Optionally | ||
# you can turn it on using a cron schedule for regular testing. | ||
# | ||
name: Tests | ||
on: | ||
pull_request: | ||
paths-ignore: | ||
- 'README.md' | ||
- 'docs/**' | ||
push: | ||
paths-ignore: | ||
- 'README.md' | ||
- 'docs/**' | ||
jobs: | ||
test: | ||
name: Client Test | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 15 | ||
strategy: | ||
fail-fast: false | ||
max-parallel: 1 | ||
matrix: | ||
# list whatever Terraform versions here you would like to support | ||
goversion: | ||
- '1.13' | ||
- '1.14' | ||
- '1.15' | ||
- '1.16' | ||
- '1.17' | ||
- '1.18' | ||
steps: | ||
- name: Set up Go | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: ${{ matrix.goversion }} | ||
id: go | ||
|
||
- name: Check out code into the Go module directory | ||
uses: actions/checkout@v3 | ||
|
||
- name: Get dependencies | ||
run: | | ||
go mod download | ||
- name: client tests | ||
timeout-minutes: 10 | ||
env: | ||
AUTHLETE_API_SERVER: ${{ secrets.AUTHLETE_API_SERVER }} | ||
AUTHLETE_SO_KEY: ${{ secrets.AUTHLETE_SO_KEY }} | ||
AUTHLETE_SO_SECRET: ${{ secrets.AUTHLETE_SO_SECRET }} | ||
|
||
run: | | ||
go test -v -cover ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
package testing | ||
|
||
import ( | ||
"strconv" | ||
"testing" | ||
|
||
authlete "github.com/authlete/openapi-for-go" | ||
) | ||
|
||
func TestClientLifecycle(t *testing.T) { | ||
|
||
authleteClient, srv, apiCtx, newCli := createTestClient(t) | ||
apiKey := strconv.FormatInt(srv.GetApiKey(), 10) | ||
defer ensureDeleteService(apiKey, authleteClient) | ||
|
||
client_id := strconv.FormatInt(newCli.GetClientId(), 10) | ||
client_secret := newCli.GetClientSecret() | ||
|
||
// update the client | ||
|
||
att1 := authlete.NewPair() | ||
att1.SetKey("key1") | ||
att1.SetValue("val1") | ||
newCli.SetAttributes([]authlete.Pair{*att1}) | ||
newCli.SetDescription("Changed Description") | ||
|
||
updCli, _, errUp := authleteClient.ClientManagementApi.ClientUpdateApi(apiCtx, client_id).Client(*newCli).Execute() | ||
|
||
if errUp != nil { | ||
t.Errorf("An error occured when updating a testing client: %q", errUp.Error()) | ||
} | ||
|
||
if len(updCli.GetAttributes()) == 0 { | ||
t.Errorf("Changes on attributes not reflected on returned client from update client api") | ||
} | ||
|
||
// get the client | ||
|
||
getCli, _, errGet := authleteClient.ClientManagementApi.ClientGetApi(apiCtx, client_id).Execute() | ||
|
||
if errGet != nil { | ||
t.Errorf("An error occured when retrieving the testing client: %q", errGet.Error()) | ||
} | ||
|
||
if updCli.GetDescription() != getCli.GetDescription() { | ||
t.Errorf("The change to description is not reflected on retrieved client ") | ||
} | ||
|
||
// list the clients | ||
|
||
cliList, _, errList := authleteClient.ClientManagementApi.ClientGetListApi(apiCtx).Start(0).End(100).Execute() | ||
|
||
if errList != nil { | ||
t.Errorf("An error occured when retrieving the client list: %q", errList.Error()) | ||
} | ||
|
||
found := false | ||
var cli authlete.Client | ||
for _, cli = range cliList.GetClients() { | ||
if cli.GetClientId() == newCli.GetClientId() { | ||
found = true | ||
break | ||
} | ||
} | ||
if !found { | ||
t.Errorf("Could not find the created client on client list") | ||
} | ||
if cli.GetClientSecret() != client_secret { | ||
t.Errorf("The client secret was changed on previous calls") | ||
} | ||
|
||
// delete the client | ||
|
||
_, errDelete := authleteClient.ClientManagementApi.ClientDeleteApi(apiCtx, client_id).Execute() | ||
|
||
if errDelete != nil { | ||
t.Errorf("An error occured when deleting the test client: %q", errDelete.Error()) | ||
} | ||
|
||
// check if it was deleted | ||
|
||
cliList, _, errList = authleteClient.ClientManagementApi.ClientGetListApi(apiCtx).Start(0).End(100).Execute() | ||
|
||
if errList != nil { | ||
t.Errorf("An error occured when retrieving the client list: %q", errList.Error()) | ||
} | ||
|
||
found = false | ||
for _, cli = range cliList.GetClients() { | ||
if cli.GetClientId() == newCli.GetClientId() { | ||
found = true | ||
break | ||
} | ||
} | ||
if found { | ||
t.Errorf("deleted client still on client list") | ||
} | ||
} | ||
|
||
func TestSecretManagement(t *testing.T) { | ||
authleteClient, srv, apiCtx, newCli := createTestClient(t) | ||
apiKey := strconv.FormatInt(srv.GetApiKey(), 10) | ||
defer ensureDeleteService(apiKey, authleteClient) | ||
|
||
client_id := strconv.FormatInt(newCli.GetClientId(), 10) | ||
|
||
client_secret_up := "jsadfkljhfadkjsadfj1" | ||
req := authlete.NewClientSecretUpdateRequest(client_secret_up) | ||
resp, _, err := authleteClient.ClientManagementApi.ClientSecretUpdateApi(apiCtx, client_id).ClientSecretUpdateRequest(*req).Execute() | ||
|
||
if err != nil { | ||
t.Errorf("An error occured when updating the secret: %q", err.Error()) | ||
} | ||
|
||
if resp.GetNewClientSecret() != client_secret_up { | ||
t.Errorf("new secret not matching %q - expected %q", resp.GetNewClientSecret(), client_secret_up) | ||
} | ||
|
||
respRefresh, _, errRefresh := authleteClient.ClientManagementApi.ClientSecretRefreshApi(apiCtx, client_id).Execute() | ||
|
||
if errRefresh != nil { | ||
t.Errorf("An error occured when updating the secret: %q", errRefresh.Error()) | ||
} | ||
|
||
if respRefresh.GetOldClientSecret() != client_secret_up { | ||
t.Errorf("old secret not matching %q - expected %q", respRefresh.GetOldClientSecret(), client_secret_up) | ||
} | ||
|
||
if respRefresh.GetOldClientSecret() == respRefresh.GetNewClientSecret() { | ||
t.Errorf("old secret and new secret are matching %q", respRefresh.GetOldClientSecret()) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package testing | ||
|
||
import ( | ||
"strconv" | ||
"testing" | ||
|
||
authlete "github.com/authlete/openapi-for-go" | ||
) | ||
|
||
func TestServiceLifecycle(t *testing.T) { | ||
|
||
authleteClient := createClient() | ||
testservice := authorizationCodeDTO() | ||
auth := createSOContext() | ||
srv, _, err := authleteClient.ServiceManagementApi.ServiceCreateApi(auth).Service(*testservice).Execute() | ||
|
||
if err != nil { | ||
t.Errorf("An error occured when create a service: %q", err.Error()) | ||
} | ||
|
||
if srv.GetApiKey() == 0 { | ||
t.Error("Created service has no apikey") | ||
} | ||
|
||
key := strconv.FormatInt(srv.GetApiKey(), 10) | ||
defer ensureDeleteService(key, authleteClient) | ||
|
||
srv.SetDescription("Changed Description") | ||
if srv.GetDescription() == testservice.GetDescription() { | ||
t.Error("Create service method is updating in place the return") | ||
} | ||
|
||
authleteClient.ServiceManagementApi.ServiceUpdateApi(auth, key).Service(*srv).Execute() | ||
|
||
getSrv, _, errGet := authleteClient.ServiceManagementApi.ServiceGetApi(auth, key).Execute() | ||
if errGet != nil { | ||
t.Errorf("An error occured when create a service: %q", errGet.Error()) | ||
} | ||
|
||
if getSrv.GetDescription() != "Changed Description" { | ||
t.Error("Update service method did not succeed") | ||
} | ||
|
||
founded := false | ||
var srvFromList authlete.Service | ||
srvList, _, errList := authleteClient.ServiceManagementApi.ServiceGetListApi(auth).Start(0).End(1000).Execute() | ||
if errList != nil { | ||
t.Errorf("An error occured when getting the service list: %q", errList.Error()) | ||
} | ||
for _, srvFromList = range srvList.GetServices() { | ||
if srvFromList.GetApiKey() == srv.GetApiKey() { | ||
founded = true | ||
break | ||
} | ||
} | ||
if !founded { | ||
t.Error("Created service not found on the service list") | ||
} | ||
|
||
authleteClient.ServiceManagementApi.ServiceDeleteApi(auth, key).Execute() | ||
|
||
srvList, _, errList = authleteClient.ServiceManagementApi.ServiceGetListApi(auth).Start(0).End(1000).Execute() | ||
|
||
if errList != nil { | ||
t.Errorf("An error occured when getting the service list: %q", errList.Error()) | ||
} | ||
founded = false | ||
for _, srvFromList = range srvList.GetServices() { | ||
if srvFromList.GetApiKey() == srv.GetApiKey() { | ||
founded = true | ||
break | ||
} | ||
} | ||
if founded { | ||
t.Error("Delete service not working, as it was found on the service list") | ||
} | ||
|
||
} |
Oops, something went wrong.