- Add support for the OAuth Device Authorization Flow (RFC 8628) in the OpenAPI service, allowing devices with limited input capabilities to obtain authorization. - Implement `DeviceAuthorization()` and `AuthorizeDevice()` methods to handle device and user code generation, storage, and authorization. - Update the OAuth endpoints to include `/device/authorize` for user code authorization and fix the discovery endpoint path for device authorization. - Introduce MongoDB service in CI workflows for testing and enhance the unit test workflow with Redis setup. - Update Go module dependencies to include necessary packages for the new features. This commit significantly advances the OAuth capabilities of the application, enabling a more flexible authorization process for devices.
57 lines
1.2 KiB
Go
57 lines
1.2 KiB
Go
package engine
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestGetMachineID_Deterministic(t *testing.T) {
|
|
info1, err := GetMachineID()
|
|
if err != nil {
|
|
t.Fatalf("GetMachineID() returned error: %v", err)
|
|
}
|
|
|
|
info2, err := GetMachineID()
|
|
if err != nil {
|
|
t.Fatalf("GetMachineID() second call returned error: %v", err)
|
|
}
|
|
|
|
if info1.ID != info2.ID {
|
|
t.Errorf("GetMachineID() not deterministic: %q != %q", info1.ID, info2.ID)
|
|
}
|
|
}
|
|
|
|
func TestGetMachineID_Format(t *testing.T) {
|
|
info, err := GetMachineID()
|
|
if err != nil {
|
|
t.Fatalf("GetMachineID() returned error: %v", err)
|
|
}
|
|
|
|
if !strings.HasPrefix(info.ID, "yao-cli-") {
|
|
t.Errorf("ID should have prefix 'yao-cli-', got %q", info.ID)
|
|
}
|
|
|
|
// "yao-cli-" (8) + 32 hex chars = 40
|
|
if len(info.ID) != 40 {
|
|
t.Errorf("ID should be 40 chars, got %d: %q", len(info.ID), info.ID)
|
|
}
|
|
|
|
if info.Hostname == "" {
|
|
t.Error("Hostname should not be empty")
|
|
}
|
|
|
|
if info.Platform == "" {
|
|
t.Error("Platform should not be empty")
|
|
}
|
|
}
|
|
|
|
func TestGetMachineID_NonEmpty(t *testing.T) {
|
|
info, err := GetMachineID()
|
|
if err != nil {
|
|
t.Fatalf("GetMachineID() returned error: %v", err)
|
|
}
|
|
|
|
if info.ID == "" {
|
|
t.Error("ID should not be empty")
|
|
}
|
|
}
|