PostgreSQL backup tool with Point-In-Time-Recovery and restore verification
TypeScript backupbackupsdatabasedatabase-backupdevopsdockergolangkubernetesmariadbmongodbmysqlpgpostgrespostgresqls3self-hostedsystem-administrationtoolsweb-ui
test HTTP proxy
Грицик Евгенийf1b33cffb531
diff --git a/backend/internal/features/notifiers/controller_test.go b/backend/internal/features/notifiers/controller_test.goindex 816a9bf2..445f6b96 100644--- a/backend/internal/features/notifiers/controller_test.go+++ b/backend/internal/features/notifiers/controller_test.go@@ -467,8 +467,10 @@ func Test_NotifierSensitiveDataLifecycle_AllTypes(t *testing.T) {Name: "Test Telegram Notifier",NotifierType: NotifierTypeTelegram,TelegramNotifier: &telegram_notifier.TelegramNotifier{- BotToken: "original-bot-token-12345",- TargetChatID: "123456789",+ BotToken: "original-bot-token-12345",+ TargetChatID: "123456789",+ IsHTTPProxyEnabled: true,+ HTTPProxyURL: "http://user:[email protected]:3128",},}},@@ -479,8 +481,10 @@ func Test_NotifierSensitiveDataLifecycle_AllTypes(t *testing.T) {Name: "Updated Telegram Notifier",NotifierType: NotifierTypeTelegram,TelegramNotifier: &telegram_notifier.TelegramNotifier{- BotToken: "",- TargetChatID: "987654321",+ BotToken: "",+ TargetChatID: "987654321",+ IsHTTPProxyEnabled: true,+ HTTPProxyURL: "",},}},@@ -492,9 +496,21 @@ func Test_NotifierSensitiveDataLifecycle_AllTypes(t *testing.T) {)decrypted := decryptField(t, notifier.TelegramNotifier.BotToken)assert.Equal(t, "original-bot-token-12345", decrypted)++ assert.True(+ t,+ isEncrypted(notifier.TelegramNotifier.HTTPProxyURL),+ "HTTPProxyURL should be encrypted in DB",+ )+ decryptedProxyURL := decryptField(t, notifier.TelegramNotifier.HTTPProxyURL)+ assert.Equal(t, "http://user:[email protected]:3128", decryptedProxyURL)+ assert.True(t, notifier.TelegramNotifier.IsHTTPProxyEnabled)},verifyHiddenData: func(t *testing.T, notifier *Notifier) {assert.Equal(t, "", notifier.TelegramNotifier.BotToken)+ assert.Equal(t, "", notifier.TelegramNotifier.HTTPProxyURL)+ assert.True(t, notifier.TelegramNotifier.IsHTTPProxyEnabled)+ assert.True(t, notifier.TelegramNotifier.HasHTTPProxyURL)},},{@@ -818,8 +834,10 @@ func Test_CreateNotifier_AllSensitiveFieldsEncryptedInDB(t *testing.T) {Name: "Test Telegram",NotifierType: NotifierTypeTelegram,TelegramNotifier: &telegram_notifier.TelegramNotifier{- BotToken: "plain-telegram-token-123",- TargetChatID: "123456789",+ BotToken: "plain-telegram-token-123",+ TargetChatID: "123456789",+ IsHTTPProxyEnabled: true,+ HTTPProxyURL: "http://proxy.example.com:8080",},}},@@ -831,6 +849,14 @@ func Test_CreateNotifier_AllSensitiveFieldsEncryptedInDB(t *testing.T) {)decrypted := decryptField(t, notifier.TelegramNotifier.BotToken)assert.Equal(t, "plain-telegram-token-123", decrypted)++ assert.True(+ t,+ isEncrypted(notifier.TelegramNotifier.HTTPProxyURL),+ "HTTPProxyURL should be encrypted",+ )+ decryptedProxyURL := decryptField(t, notifier.TelegramNotifier.HTTPProxyURL)+ assert.Equal(t, "http://proxy.example.com:8080", decryptedProxyURL)},},{diff --git a/backend/internal/features/notifiers/models/telegram/model_test.go b/backend/internal/features/notifiers/models/telegram/model_test.gonew file mode 100644index 00000000..c93ddcbf--- /dev/null+++ b/backend/internal/features/notifiers/models/telegram/model_test.go@@ -0,0 +1,77 @@+package telegram_notifier++import (+ "net/http"+ "testing"++ "github.com/stretchr/testify/assert"+ "github.com/stretchr/testify/require"+)++type passthroughEncryptor struct{}++func (p passthroughEncryptor) Encrypt(plaintext string) (string, error) {+ return plaintext, nil+}++func (p passthroughEncryptor) Decrypt(ciphertext string) (string, error) {+ return ciphertext, nil+}++func Test_Validate_WhenHTTPProxyEnabledWithoutURL_ReturnsError(t *testing.T) {+ notifier := &TelegramNotifier{+ BotToken: "token",+ TargetChatID: "123456",+ IsHTTPProxyEnabled: true,+ }++ err := notifier.Validate(passthroughEncryptor{})++ require.Error(t, err)+ assert.Contains(t, err.Error(), "HTTP proxy URL is required")+}++func Test_Validate_WhenHTTPProxyURLIsNotHTTP_ReturnsError(t *testing.T) {+ notifier := &TelegramNotifier{+ BotToken: "token",+ TargetChatID: "123456",+ IsHTTPProxyEnabled: true,+ HTTPProxyURL: "https://proxy.example.com:3128",+ }++ err := notifier.Validate(passthroughEncryptor{})++ require.Error(t, err)+ assert.Contains(t, err.Error(), "valid http:// URL")+}++func Test_BuildHTTPClient_WhenHTTPProxyEnabled_UsesConfiguredProxy(t *testing.T) {+ notifier := &TelegramNotifier{+ IsHTTPProxyEnabled: true,+ HTTPProxyURL: "http://user:[email protected]:3128",+ }++ client, err := notifier.buildHTTPClient(passthroughEncryptor{})+ require.NoError(t, err)++ transport, ok := client.Transport.(*http.Transport)+ require.True(t, ok)+ require.NotNil(t, transport.Proxy)++ req, err := http.NewRequest(http.MethodGet, "https://api.telegram.org", nil)+ require.NoError(t, err)++ proxyURL, err := transport.Proxy(req)+ require.NoError(t, err)+ require.NotNil(t, proxyURL)+ assert.Equal(t, "http://user:[email protected]:3128", proxyURL.String())+}++func Test_BuildHTTPClient_WhenHTTPProxyDisabled_UsesDefaultTransport(t *testing.T) {+ notifier := &TelegramNotifier{}++ client, err := notifier.buildHTTPClient(passthroughEncryptor{})++ require.NoError(t, err)+ assert.Nil(t, client.Transport)+}diff --git a/frontend/src/entity/notifiers/models/telegram/validateTelegramNotifier.test.ts b/frontend/src/entity/notifiers/models/telegram/validateTelegramNotifier.test.tsnew file mode 100644index 00000000..3d90fb26--- /dev/null+++ b/frontend/src/entity/notifiers/models/telegram/validateTelegramNotifier.test.ts@@ -0,0 +1,48 @@+import { describe, expect, it } from 'vitest';++import { validateTelegramNotifier } from './validateTelegramNotifier';++describe('validateTelegramNotifier', () => {+ it('requires proxy URL when HTTP proxy is enabled for a new notifier', () => {+ expect(+ validateTelegramNotifier(true, {+ botToken: 'token',+ targetChatId: '123456',+ isHttpProxyEnabled: true,+ }),+ ).toBe(false);+ });++ it('allows an existing hidden proxy URL', () => {+ expect(+ validateTelegramNotifier(false, {+ botToken: '',+ targetChatId: '123456',+ isHttpProxyEnabled: true,+ hasHttpProxyUrl: true,+ }),+ ).toBe(true);+ });++ it('rejects non-http proxy URLs', () => {+ expect(+ validateTelegramNotifier(true, {+ botToken: 'token',+ targetChatId: '123456',+ isHttpProxyEnabled: true,+ httpProxyUrl: 'https://proxy.example.com:3128',+ }),+ ).toBe(false);+ });++ it('allows valid http proxy URLs', () => {+ expect(+ validateTelegramNotifier(true, {+ botToken: 'token',+ targetChatId: '123456',+ isHttpProxyEnabled: true,+ httpProxyUrl: 'http://user:[email protected]:3128',+ }),+ ).toBe(true);+ });+});diff --git a/frontend/src/entity/notifiers/models/telegram/validateTelegramNotifier.ts b/frontend/src/entity/notifiers/models/telegram/validateTelegramNotifier.tsindex 2a1a2d3f..ce44999e 100644--- a/frontend/src/entity/notifiers/models/telegram/validateTelegramNotifier.ts+++ b/frontend/src/entity/notifiers/models/telegram/validateTelegramNotifier.ts@@ -17,5 +17,22 @@ export const validateTelegramNotifier = (return false;}+ if (notifier.isHttpProxyEnabled) {+ if (!notifier.httpProxyUrl && !notifier.hasHttpProxyUrl) {+ return false;+ }++ if (notifier.httpProxyUrl) {+ try {+ const proxyUrl = new URL(notifier.httpProxyUrl);+ if (proxyUrl.protocol !== 'http:' || !proxyUrl.host) {+ return false;+ }+ } catch {+ return false;+ }+ }+ }+return true;};