opencode-deepseek-auth 1.0.3 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,122 @@
1
+ "use strict";
2
+ /**
3
+ * Test script to validate authentication flow in the DeepSeek Auth plugin
4
+ * This script simulates different authentication scenarios to ensure
5
+ * the plugin correctly handles various input formats
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ // Test scenarios
9
+ async function runTests() {
10
+ console.log("Running authentication flow tests...\n");
11
+ // Test 1: Email:password format (should trigger login flow)
12
+ console.log("Test 1: Valid email:password format");
13
+ try {
14
+ const mockAuth = {
15
+ apiKey: "test@example.com:mypassword123",
16
+ type: "deepseek-email-password",
17
+ provider: "deepseek"
18
+ };
19
+ // Simulate the authentication logic
20
+ const parts = mockAuth.apiKey.split(':');
21
+ if (parts.length === 2) {
22
+ const [identifier, password] = parts;
23
+ console.log(` - Detected email:password format: ${identifier}:${password.replace(/./g, '*')}`);
24
+ // Check if looks like valid email format
25
+ const isEmailFormat = identifier.includes('@');
26
+ const isPasswordReasonable = password.length >= 6;
27
+ if (isEmailFormat && isPasswordReasonable) {
28
+ console.log(" ✓ Correctly identified as email:password format");
29
+ }
30
+ else {
31
+ console.log(" ✗ Incorrectly rejected as email:password format");
32
+ }
33
+ }
34
+ }
35
+ catch (error) {
36
+ console.log(` ✗ Error: ${error}`);
37
+ }
38
+ console.log();
39
+ // Test 2: Regular API key (should pass through directly)
40
+ console.log("Test 2: Regular API key format");
41
+ try {
42
+ const mockAuth = {
43
+ apiKey: "sk-deepseek-actual-api-token-here",
44
+ type: "standard-api-key"
45
+ };
46
+ const parts = mockAuth.apiKey.split(':');
47
+ if (parts.length === 1) {
48
+ console.log(` - Detected as regular API key: ${mockAuth.apiKey.substring(0, 15)}...`);
49
+ console.log(" ✓ Correctly treated as direct API key");
50
+ }
51
+ else if (parts.length === 2) {
52
+ // Check if it's actually email:password
53
+ const [identifier, password] = parts;
54
+ const isEmailFormat = identifier.includes('@');
55
+ if (!isEmailFormat) {
56
+ console.log(` - Found colon-separated key but not email format: ${mockAuth.apiKey}`);
57
+ console.log(" ✓ Correctly identified as non-email:password format API key");
58
+ }
59
+ else {
60
+ console.log(" ⚠ May be incorrectly treated as email:password");
61
+ }
62
+ }
63
+ }
64
+ catch (error) {
65
+ console.log(` ✗ Error: ${error}`);
66
+ }
67
+ console.log();
68
+ // Test 3: Invalid email:password (wrong format)
69
+ console.log("Test 3: Invalid email:password format");
70
+ try {
71
+ const mockAuth = {
72
+ apiKey: "not-an-email:simple",
73
+ type: "deepseek-email-password",
74
+ provider: "deepseek"
75
+ };
76
+ const parts = mockAuth.apiKey.split(':');
77
+ if (parts.length === 2) {
78
+ const [identifier, password] = parts;
79
+ const isEmailFormat = identifier.includes('@');
80
+ const isPasswordReasonable = password.length >= 6;
81
+ if (isEmailFormat && isPasswordReasonable) {
82
+ console.log(" ✓ Correctly validated format");
83
+ }
84
+ else {
85
+ console.log(" ✓ Correctly rejected invalid format");
86
+ }
87
+ }
88
+ }
89
+ catch (error) {
90
+ console.log(` ✗ Error: ${error}`);
91
+ }
92
+ console.log();
93
+ // Test 4: Phone:password format
94
+ console.log("Test 4: Phone:password format");
95
+ try {
96
+ const mockAuth = {
97
+ apiKey: "+1234567890:myphonepass",
98
+ type: "deepseek-email-password",
99
+ provider: "deepseek"
100
+ };
101
+ const parts = mockAuth.apiKey.split(':');
102
+ if (parts.length === 2) {
103
+ const [identifier, password] = parts;
104
+ const isPhoneFormat = /^[0-9+\-\s()]+$/.test(identifier);
105
+ const isPasswordReasonable = password.length >= 6;
106
+ if (isPhoneFormat && isPasswordReasonable) {
107
+ console.log(` - Identified as phone:password format: ${identifier}:${password.replace(/./g, '*')}`);
108
+ console.log(" ✓ Correctly identified phone:password format");
109
+ }
110
+ else {
111
+ console.log(" ✓ Correctly rejected invalid phone:password format");
112
+ }
113
+ }
114
+ }
115
+ catch (error) {
116
+ console.log(` ✗ Error: ${error}`);
117
+ }
118
+ console.log();
119
+ console.log("Authentication flow tests completed.");
120
+ }
121
+ // Run the tests
122
+ runTests().catch(console.error);
@@ -0,0 +1,142 @@
1
+ /**
2
+ * Test script to validate authentication flow in the DeepSeek Auth plugin
3
+ * This script simulates different authentication scenarios to ensure
4
+ * the plugin correctly handles various input formats
5
+ */
6
+
7
+ import { DeepSeekAuthPlugin } from './src/plugin';
8
+ import { loginDeepSeek } from './src/deepseek/auth';
9
+
10
+ // Mock plugin context and types for testing
11
+ interface MockAuth {
12
+ apiKey?: string;
13
+ type?: string;
14
+ provider?: string;
15
+ }
16
+
17
+ interface MockProvider {
18
+ models?: Record<string, any>;
19
+ id?: string;
20
+ options?: Record<string, any>;
21
+ }
22
+
23
+ // Test scenarios
24
+ async function runTests() {
25
+ console.log("Running authentication flow tests...\n");
26
+
27
+ // Test 1: Email:password format (should trigger login flow)
28
+ console.log("Test 1: Valid email:password format");
29
+ try {
30
+ const mockAuth: MockAuth = {
31
+ apiKey: "test@example.com:mypassword123",
32
+ type: "deepseek-email-password",
33
+ provider: "deepseek"
34
+ };
35
+
36
+ // Simulate the authentication logic
37
+ const parts = mockAuth.apiKey!.split(':');
38
+ if (parts.length === 2) {
39
+ const [identifier, password] = parts;
40
+ console.log(` - Detected email:password format: ${identifier}:${password.replace(/./g, '*')}`);
41
+
42
+ // Check if looks like valid email format
43
+ const isEmailFormat = identifier.includes('@');
44
+ const isPasswordReasonable = password.length >= 6;
45
+
46
+ if (isEmailFormat && isPasswordReasonable) {
47
+ console.log(" ✓ Correctly identified as email:password format");
48
+ } else {
49
+ console.log(" ✗ Incorrectly rejected as email:password format");
50
+ }
51
+ }
52
+ } catch (error) {
53
+ console.log(` ✗ Error: ${error}`);
54
+ }
55
+ console.log();
56
+
57
+ // Test 2: Regular API key (should pass through directly)
58
+ console.log("Test 2: Regular API key format");
59
+ try {
60
+ const mockAuth: MockAuth = {
61
+ apiKey: "sk-deepseek-actual-api-token-here",
62
+ type: "standard-api-key"
63
+ };
64
+
65
+ const parts = mockAuth.apiKey!.split(':');
66
+ if (parts.length === 1) {
67
+ console.log(` - Detected as regular API key: ${mockAuth.apiKey!.substring(0, 15)}...`);
68
+ console.log(" ✓ Correctly treated as direct API key");
69
+ } else if (parts.length === 2) {
70
+ // Check if it's actually email:password
71
+ const [identifier, password] = parts;
72
+ const isEmailFormat = identifier.includes('@');
73
+ if (!isEmailFormat) {
74
+ console.log(` - Found colon-separated key but not email format: ${mockAuth.apiKey}`);
75
+ console.log(" ✓ Correctly identified as non-email:password format API key");
76
+ } else {
77
+ console.log(" ⚠ May be incorrectly treated as email:password");
78
+ }
79
+ }
80
+ } catch (error) {
81
+ console.log(` ✗ Error: ${error}`);
82
+ }
83
+ console.log();
84
+
85
+ // Test 3: Invalid email:password (wrong format)
86
+ console.log("Test 3: Invalid email:password format");
87
+ try {
88
+ const mockAuth: MockAuth = {
89
+ apiKey: "not-an-email:simple",
90
+ type: "deepseek-email-password",
91
+ provider: "deepseek"
92
+ };
93
+
94
+ const parts = mockAuth.apiKey!.split(':');
95
+ if (parts.length === 2) {
96
+ const [identifier, password] = parts;
97
+ const isEmailFormat = identifier.includes('@');
98
+ const isPasswordReasonable = password.length >= 6;
99
+
100
+ if (isEmailFormat && isPasswordReasonable) {
101
+ console.log(" ✓ Correctly validated format");
102
+ } else {
103
+ console.log(" ✓ Correctly rejected invalid format");
104
+ }
105
+ }
106
+ } catch (error) {
107
+ console.log(` ✗ Error: ${error}`);
108
+ }
109
+ console.log();
110
+
111
+ // Test 4: Phone:password format
112
+ console.log("Test 4: Phone:password format");
113
+ try {
114
+ const mockAuth: MockAuth = {
115
+ apiKey: "+1234567890:myphonepass",
116
+ type: "deepseek-email-password",
117
+ provider: "deepseek"
118
+ };
119
+
120
+ const parts = mockAuth.apiKey!.split(':');
121
+ if (parts.length === 2) {
122
+ const [identifier, password] = parts;
123
+ const isPhoneFormat = /^[0-9+\-\s()]+$/.test(identifier);
124
+ const isPasswordReasonable = password.length >= 6;
125
+
126
+ if (isPhoneFormat && isPasswordReasonable) {
127
+ console.log(` - Identified as phone:password format: ${identifier}:${password.replace(/./g, '*')}`);
128
+ console.log(" ✓ Correctly identified phone:password format");
129
+ } else {
130
+ console.log(" ✓ Correctly rejected invalid phone:password format");
131
+ }
132
+ }
133
+ } catch (error) {
134
+ console.log(` ✗ Error: ${error}`);
135
+ }
136
+ console.log();
137
+
138
+ console.log("Authentication flow tests completed.");
139
+ }
140
+
141
+ // Run the tests
142
+ runTests().catch(console.error);