-
Notifications
You must be signed in to change notification settings - Fork 2
fix: 20 - исправлена ошибка аутентификации #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
67a9a0d
1ff12c4
0c77f9b
0d45889
ad7affb
d117a5d
a6ea738
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| import { | ||
| TokenAuthProvider, | ||
| FormAuthProvider, | ||
| AuthProviderFactory, | ||
| AuthProviderType | ||
| } from '../src/onegetjs/auth' | ||
| import { HttpClient } from '../src/onegetjs/httpClient' | ||
|
|
||
| describe('Auth Providers', () => { | ||
| const login = process.env.ONEC_USERNAME ?? 'test' | ||
| const password = process.env.ONEC_PASSWORD ?? 'test' | ||
|
|
||
| it('TokenAuthProvider should be instantiable', () => { | ||
| const provider = new TokenAuthProvider(login, password) | ||
| expect(provider).toBeDefined() | ||
| expect(typeof provider.authenticate).toBe('function') | ||
| }) | ||
|
|
||
| it('FormAuthProvider should be instantiable', () => { | ||
| const provider = new FormAuthProvider(login, password) | ||
| expect(provider).toBeDefined() | ||
| expect(typeof provider.authenticate).toBe('function') | ||
| }) | ||
|
|
||
| it('AuthProviderFactory should create TOKEN provider', () => { | ||
| const provider = AuthProviderFactory.create({ | ||
| username: login, | ||
| password: password, | ||
| preferredProvider: AuthProviderType.TOKEN | ||
| }) | ||
|
|
||
| expect(provider).toBeDefined() | ||
| expect(provider).toBeInstanceOf(TokenAuthProvider) | ||
| }) | ||
|
|
||
| it('AuthProviderFactory should create FORM provider by default', () => { | ||
| const provider = AuthProviderFactory.create({ | ||
| username: login, | ||
| password: password | ||
| }) | ||
|
|
||
| expect(provider).toBeInstanceOf(FormAuthProvider) | ||
| }) | ||
|
|
||
| it('AuthProviderFactory should respect FORM provider', () => { | ||
| const provider = AuthProviderFactory.create({ | ||
| username: login, | ||
| password: password, | ||
| preferredProvider: AuthProviderType.FORM | ||
| }) | ||
|
|
||
| expect(provider).toBeInstanceOf(FormAuthProvider) | ||
| }) | ||
|
|
||
| // Тесты реальной аутентификации (требуют переменные окружения) | ||
| describe('Real Authentication', () => { | ||
| const hasCredentials = | ||
| login && password && login !== 'test' && password !== 'test' | ||
|
|
||
| it('TokenAuthProvider should attempt authentication', async () => { | ||
| if (!hasCredentials) { | ||
| console.log('Skipping TokenAuthProvider test - no credentials') | ||
| return | ||
| } | ||
|
|
||
| const provider = new TokenAuthProvider(login, password) | ||
| const httpClient = new HttpClient() | ||
| try { | ||
| await provider.authenticate(httpClient) | ||
| // Если дошли сюда - аутентификация прошла | ||
| expect(true).toBe(true) | ||
| } catch (error) { | ||
| // Ожидаем ошибку, но проверяем что это правильная ошибка аутентификации | ||
| expect(error).toBeDefined() | ||
| expect((error as Error).message.toLowerCase()).toContain( | ||
| 'authentication' | ||
| ) | ||
| } | ||
| }, 30000) | ||
|
|
||
| it('FormAuthProvider should attempt authentication', async () => { | ||
| const provider = new FormAuthProvider(login, password) | ||
| const httpClient = new HttpClient() | ||
| await provider.authenticate(httpClient) | ||
| // Если дошли сюда - аутентификация прошла | ||
| expect(true).toBe(true) | ||
| }, 30000) | ||
|
Comment on lines
+81
to
+87
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Skip or handle FormAuthProvider auth when credentials are missing. This test runs even when 🧪 Suggested fix- it('FormAuthProvider should attempt authentication', async () => {
- const provider = new FormAuthProvider(login, password)
- const httpClient = new HttpClient()
- await provider.authenticate(httpClient)
- // Если дошли сюда - аутентификация прошла
- expect(true).toBe(true)
- }, 30000)
+ it('FormAuthProvider should attempt authentication', async () => {
+ if (!hasCredentials) {
+ console.log('Skipping FormAuthProvider test - no credentials')
+ return
+ }
+ const provider = new FormAuthProvider(login, password)
+ const httpClient = new HttpClient()
+ await provider.authenticate(httpClient)
+ // Если дошли сюда - аутентификация прошла
+ expect(true).toBe(true)
+ }, 30000)🤖 Prompt for AI Agents |
||
|
|
||
| it('AuthProviderFactory should create working provider', async () => { | ||
| if (!hasCredentials) { | ||
| console.log('Skipping AuthProviderFactory test - no credentials') | ||
| return | ||
| } | ||
|
|
||
| const provider = AuthProviderFactory.create({ | ||
| username: login, | ||
| password: password | ||
| }) | ||
|
|
||
| const httpClient = new HttpClient() | ||
| // Проверяем что провайдер может выполнять аутентификацию | ||
| try { | ||
| await provider.authenticate(httpClient) | ||
| const response = await httpClient.get('https://releases.1c.ru') | ||
| expect(response.status).toBe(200) | ||
| } catch (error) { | ||
| // Ожидаем ошибку из-за отсутствия аутентификации | ||
| expect(error).toBeDefined() | ||
| } | ||
| }, 30000) | ||
| }) | ||
| }) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,31 @@ | ||
| import { Client } from '../src/onegetjs/downloader' | ||
| import { AuthProviderType } from '../src/onegetjs/auth' | ||
|
|
||
| describe('downloader.ts', () => { | ||
| const login = process.env.ONEC_USERNAME ?? '' | ||
| const password = process.env.ONEC_PASSWORD ?? '' | ||
| const client = new Client(login, password) | ||
|
|
||
| it('auth', async () => { | ||
| await client.auth() | ||
| it('auth with token provider', async () => { | ||
| const client = new Client(login, password, { | ||
| preferredProvider: AuthProviderType.TOKEN | ||
| }) | ||
| try { | ||
|
Comment on lines
5
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid constructor throw when env credentials are missing.
✅ Suggested fix (placeholders)- const login = process.env.ONEC_USERNAME ?? ''
- const password = process.env.ONEC_PASSWORD ?? ''
+ const login = process.env.ONEC_USERNAME ?? 'test'
+ const password = process.env.ONEC_PASSWORD ?? 'test'🤖 Prompt for AI Agents |
||
| await client.auth() | ||
| } catch (error) { | ||
| // Ожидаем ошибку из-за отсутствия реальных учетных данных | ||
| expect(error).toBeDefined() | ||
| } | ||
| }) | ||
|
|
||
| it('auth with form provider', async () => { | ||
| const client = new Client(login, password, { | ||
| preferredProvider: AuthProviderType.FORM | ||
| }) | ||
| try { | ||
| await client.auth() | ||
| } catch (error) { | ||
| // Ожидаем ошибку из-за отсутствия реальных учетных данных | ||
| expect(error).toBeDefined() | ||
| } | ||
| }) | ||
| }) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import { versions } from '../src/onegetjs/parse' | ||
|
|
||
| describe('parse.ts', () => { | ||
| it('should parse versions from HTML', () => { | ||
| const html = ` | ||
| <table> | ||
| <tr> | ||
| <td class="versionColumn"> | ||
| <a href="/version/8.3.25.1286">8.3.25.1286</a> | ||
| </td> | ||
| </tr> | ||
| <tr> | ||
| <td class="versionColumn"> | ||
| <a href="/version/8.3.24.1500">8.3.24.1500</a> | ||
| </td> | ||
| </tr> | ||
| </table> | ||
| ` | ||
|
|
||
| const result = versions(html) | ||
| expect(result).toHaveLength(2) | ||
| expect(result[0].name).toBe('8.3.25.1286') | ||
| expect(result[1].name).toBe('8.3.24.1500') | ||
| }) | ||
| }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Relax the TokenAuthProvider error message assertion.
TokenAuthProvidercan throw errors like “Auth failed with status ...”, which won’t include “authentication”, so the assertion is brittle.🧪 Suggested fix
📝 Committable suggestion
🤖 Prompt for AI Agents