-
Notifications
You must be signed in to change notification settings - Fork 75
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 Songjf-ttk/master
test ci
- Loading branch information
Showing
30 changed files
with
1,900 additions
and
10 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
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,93 @@ | ||
// Copyright 2023 The Casdoor Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package casdoorsdk | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestAdapter(t *testing.T) { | ||
InitConfig(TestCasdoorEndpoint, TestClientId, TestClientSecret, TestJwtPublicKey, TestCasdoorOrganization, TestCasdoorApplication) | ||
|
||
name := getRandomName("adapter") | ||
|
||
// Add a new object | ||
adapter := &Adapter{ | ||
Owner: "admin", | ||
Name: name, | ||
CreatedTime: time.Now().Format(time.RFC3339), | ||
User: name, | ||
Host: "https://casdoor.org", | ||
} | ||
_, err := AddAdapter(adapter) | ||
if err != nil { | ||
t.Fatalf("Failed to add object: %v", err) | ||
} | ||
|
||
// Get all objects, check if our added object is inside the list | ||
adapters, err := GetAdapters() | ||
if err != nil { | ||
t.Fatalf("Failed to get objects: %v", err) | ||
} | ||
found := false | ||
for _, item := range adapters { | ||
if item.Name == name { | ||
found = true | ||
break | ||
} | ||
} | ||
if !found { | ||
t.Fatalf("Added object not found in list") | ||
} | ||
|
||
// Get the object | ||
adapter, err = GetAdapter(name) | ||
if err != nil { | ||
t.Fatalf("Failed to get object: %v", err) | ||
} | ||
if adapter.Name != name { | ||
t.Fatalf("Retrieved object does not match added object: %s != %s", adapter.Name, name) | ||
} | ||
|
||
// Update the object | ||
updatedUser := "Updated Casdoor Website" | ||
adapter.User = updatedUser | ||
_, err = UpdateAdapter(adapter) | ||
if err != nil { | ||
t.Fatalf("Failed to update object: %v", err) | ||
} | ||
|
||
// Validate the update | ||
updatedadapter, err := GetAdapter(name) | ||
if err != nil { | ||
t.Fatalf("Failed to get updated object: %v", err) | ||
} | ||
if updatedadapter.User != updatedUser { | ||
t.Fatalf("Failed to update object, User mismatch: %s != %s", updatedadapter.User, updatedUser) | ||
} | ||
|
||
// Delete the object | ||
_, err = DeleteAdapter(adapter) | ||
if err != nil { | ||
t.Fatalf("Failed to delete object: %v", err) | ||
} | ||
|
||
// Validate the deletion | ||
deletedadapter, err := GetAdapter(name) | ||
if err != nil || deletedadapter != nil { | ||
t.Fatalf("Failed to delete object, it's still retrievable") | ||
} | ||
} |
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
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,97 @@ | ||
// Copyright 2023 The Casdoor Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package casdoorsdk | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestCert(t *testing.T) { | ||
InitConfig(TestCasdoorEndpoint, TestClientId, TestClientSecret, TestJwtPublicKey, TestCasdoorOrganization, TestCasdoorApplication) | ||
|
||
name := getRandomName("cert") | ||
|
||
// Add a new object | ||
cert := &Cert{ | ||
Owner: "admin", | ||
Name: name, | ||
CreatedTime: time.Now().Format(time.RFC3339), | ||
DisplayName: name, | ||
Scope: "JWT", | ||
Type: "x509", | ||
CryptoAlgorithm: "RS256", | ||
BitSize: 4096, | ||
ExpireInYears: 20, | ||
} | ||
_, err := AddCert(cert) | ||
if err != nil { | ||
t.Fatalf("Failed to add object: %v", err) | ||
} | ||
|
||
// Get all objects, check if our added object is inside the list | ||
certs, err := GetCerts() | ||
if err != nil { | ||
t.Fatalf("Failed to get objects: %v", err) | ||
} | ||
found := false | ||
for _, item := range certs { | ||
if item.Name == name { | ||
found = true | ||
break | ||
} | ||
} | ||
if !found { | ||
t.Fatalf("Added object not found in list") | ||
} | ||
|
||
// Get the object | ||
cert, err = GetCert(name) | ||
if err != nil { | ||
t.Fatalf("Failed to get object: %v", err) | ||
} | ||
if cert.Name != name { | ||
t.Fatalf("Retrieved object does not match added object: %s != %s", cert.Name, name) | ||
} | ||
|
||
// Update the object | ||
updatedDisplayName := "Updated Casdoor Website" | ||
cert.DisplayName = updatedDisplayName | ||
_, err = UpdateCert(cert) | ||
if err != nil { | ||
t.Fatalf("Failed to update object: %v", err) | ||
} | ||
|
||
// Validate the update | ||
updatedcert, err := GetCert(name) | ||
if err != nil { | ||
t.Fatalf("Failed to get updated object: %v", err) | ||
} | ||
if updatedcert.DisplayName != updatedDisplayName { | ||
t.Fatalf("Failed to update object, description mismatch: %s != %s", updatedcert.DisplayName, updatedDisplayName) | ||
} | ||
|
||
// Delete the object | ||
_, err = DeleteCert(cert) | ||
if err != nil { | ||
t.Fatalf("Failed to delete object: %v", err) | ||
} | ||
|
||
// Validate the deletion | ||
deletedcert, err := GetCert(name) | ||
if err != nil || deletedcert != nil { | ||
t.Fatalf("Failed to delete object, it's still retrievable") | ||
} | ||
} |
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,31 @@ | ||
// Copyright 2023 The Casdoor Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package casdoorsdk | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestEmail(t *testing.T) { | ||
InitConfig(TestCasdoorEndpoint, TestClientId, TestClientSecret, TestJwtPublicKey, TestCasdoorOrganization, TestCasdoorApplication) | ||
|
||
email := &emailForm{ | ||
Title: "casbin", | ||
Content: "casdoor-go-sdk website test", | ||
Sender: "admin", | ||
Receivers: []string{"TestSmtpServer"}, | ||
} | ||
SendEmail(email.Title, email.Content, email.Sender, email.Receivers...) | ||
} |
File renamed without changes.
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,95 @@ | ||
// Copyright 2023 The Casdoor Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package casdoorsdk | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestEnforcer(t *testing.T) { | ||
InitConfig(TestCasdoorEndpoint, TestClientId, TestClientSecret, TestJwtPublicKey, TestCasdoorOrganization, TestCasdoorApplication) | ||
|
||
name := getRandomName("Enforcer") | ||
|
||
// Add a new object | ||
enforcer := &Enforcer{ | ||
Owner: "admin", | ||
Name: name, | ||
CreatedTime: time.Now().Format(time.RFC3339), | ||
DisplayName: name, | ||
Model: "built-in/user-model-built-in", | ||
Adapter: "built-in/user-adapter-built-in", | ||
Description: "Casdoor Website", | ||
} | ||
_, err := AddEnforcer(enforcer) | ||
if err != nil { | ||
t.Fatalf("Failed to add object: %v", err) | ||
} | ||
|
||
// Get all objects, check if our added object is inside the list | ||
Enforcers, err := GetEnforcers() | ||
if err != nil { | ||
t.Fatalf("Failed to get objects: %v", err) | ||
} | ||
found := false | ||
for _, item := range Enforcers { | ||
if item.Name == name { | ||
found = true | ||
break | ||
} | ||
} | ||
if !found { | ||
t.Fatalf("Added object not found in list") | ||
} | ||
|
||
// Get the object | ||
enforcer, err = GetEnforcer(name) | ||
if err != nil { | ||
t.Fatalf("Failed to get object: %v", err) | ||
} | ||
if enforcer.Name != name { | ||
t.Fatalf("Retrieved object does not match added object: %s != %s", enforcer.Name, name) | ||
} | ||
|
||
// Update the object | ||
updatedDescription := "Updated Casdoor Website" | ||
enforcer.Description = updatedDescription | ||
_, err = UpdateEnforcer(enforcer) | ||
if err != nil { | ||
t.Fatalf("Failed to update object: %v", err) | ||
} | ||
|
||
// Validate the update | ||
updatedEnforcer, err := GetEnforcer(name) | ||
if err != nil { | ||
t.Fatalf("Failed to get updated object: %v", err) | ||
} | ||
if updatedEnforcer.Description != updatedDescription { | ||
t.Fatalf("Failed to update object, description mismatch: %s != %s", updatedEnforcer.Description, updatedDescription) | ||
} | ||
|
||
// Delete the object | ||
_, err = DeleteEnforcer(enforcer) | ||
if err != nil { | ||
t.Fatalf("Failed to delete object: %v", err) | ||
} | ||
|
||
// Validate the deletion | ||
deletedEnforcer, err := GetEnforcer(name) | ||
if err != nil || deletedEnforcer != nil { | ||
t.Fatalf("Failed to delete object, it's still retrievable") | ||
} | ||
} |
Oops, something went wrong.