-
Notifications
You must be signed in to change notification settings - Fork 0
Adding kindling issue request integration test #256
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
Open
WendelHime
wants to merge
8
commits into
main
Choose a base branch
from
kindling-integration-test
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5acd7cd
chore: adding kindling integration test
WendelHime 4df5236
fix: adding domain to proxyless
WendelHime a717c56
feat: updating testing report integration test
WendelHime 3f289c2
feat: update default timeout
WendelHime b098435
Merge branch 'main' of github-lantern:getlantern/radiance into kindli…
WendelHime 63dcca8
feat: adding integration tests for fetching config with amp and dnstt…
WendelHime d7bf76f
adding test scenarios for dnstt and amp kindling
WendelHime 80fa000
fix: writing random log size on test log directory
WendelHime File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,243 @@ | ||
| //go:build integration | ||
| // +build integration | ||
|
|
||
| package radiance | ||
|
|
||
| import ( | ||
| "context" | ||
| "crypto/rand" | ||
| "encoding/base64" | ||
| "log/slog" | ||
| "os" | ||
| "path/filepath" | ||
| "testing" | ||
|
|
||
| "github.com/getlantern/dnstt" | ||
| "github.com/getlantern/kindling" | ||
| "github.com/getlantern/radiance/common" | ||
| "github.com/getlantern/radiance/common/reporting" | ||
| "github.com/getlantern/radiance/fronted" | ||
| "github.com/getlantern/radiance/issue" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| // TestKindlingIntegrations try to test each one of the techniques used by kindling | ||
| // for reporting issues and also trying to reach normal services. | ||
| // Please replace userID and email fields | ||
| // You can run this test by executing: `go test -tags integration -run TestKindlingIntegrations ./...` | ||
| func TestKindlingIntegrations(t *testing.T) { | ||
| slog.SetDefault(slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{ | ||
| Level: slog.LevelDebug, | ||
| }))) | ||
|
|
||
| type testCase struct { | ||
| name string | ||
| description string | ||
| userID string | ||
| locale string | ||
| email string | ||
| country string | ||
| setup func( | ||
| ctx context.Context, | ||
| t *testing.T, | ||
| dataDir string, | ||
| logger *slogWriter, | ||
| ) kindling.Kindling | ||
| assert func(t *testing.T, err error) | ||
| } | ||
|
|
||
| email := "" | ||
| userID := "" | ||
|
|
||
| tests := []testCase{ | ||
| { | ||
| name: "Fronted Kindling", | ||
| description: "fronted testing", | ||
| userID: userID, | ||
| locale: "pt-BR", | ||
| email: email, | ||
| country: "BR", | ||
| setup: func( | ||
| _ context.Context, | ||
| t *testing.T, | ||
| dataDir string, | ||
| logger *slogWriter, | ||
| ) kindling.Kindling { | ||
| f, err := fronted.NewFronted( | ||
| reporting.PanicListener, | ||
| filepath.Join(dataDir, "fronted_cache.json"), | ||
| logger, | ||
| ) | ||
| require.NoError(t, err) | ||
|
|
||
| return kindling.NewKindling( | ||
| "radiance", | ||
| kindling.WithPanicListener(reporting.PanicListener), | ||
| kindling.WithLogWriter(logger), | ||
| kindling.WithDomainFronting(f), | ||
| ) | ||
| }, | ||
| assert: func(t *testing.T, err error) { | ||
| assert.NoError(t, err) | ||
| }, | ||
| }, | ||
| { | ||
| name: "Proxyless Kindling", | ||
| description: "proxyless testing", | ||
| userID: userID, | ||
| locale: "pt-BR", | ||
| email: email, | ||
| country: "BR", | ||
| setup: func( | ||
| _ context.Context, | ||
| t *testing.T, | ||
| dataDir string, | ||
| logger *slogWriter, | ||
| ) kindling.Kindling { | ||
| return kindling.NewKindling( | ||
| "radiance", | ||
| kindling.WithPanicListener(reporting.PanicListener), | ||
| kindling.WithLogWriter(logger), | ||
| kindling.WithProxyless("df.iantem.io", "api.getiantem.org"), | ||
| ) | ||
| }, | ||
| assert: func(t *testing.T, err error) { | ||
| assert.NoError(t, err) | ||
| }, | ||
| }, | ||
| { | ||
| name: "DNSTT Kindling", | ||
| description: "dnstt testing", | ||
| userID: userID, | ||
| locale: "pt-BR", | ||
| email: email, | ||
| country: "BR", | ||
| setup: func( | ||
| _ context.Context, | ||
| t *testing.T, | ||
| dataDir string, | ||
| logger *slogWriter, | ||
| ) kindling.Kindling { | ||
| cli, err := dnstt.NewDNSTT( | ||
| dnstt.WithDoH("https://cloudflare-dns.com/dns-query"), | ||
| dnstt.WithTunnelDomain("t.iantem.io"), | ||
| dnstt.WithPublicKey("405eb9e22d806e3a0a8e667c6665a321c8a6a35fa680ed814716a66d7ad84977"), | ||
| ) | ||
| require.NoError(t, err) | ||
| dnsTunnel2, err := dnstt.NewDNSTT( | ||
| dnstt.WithTunnelDomain("t.iantem.io"), | ||
| dnstt.WithDoH("https://dns.adguard-dns.com/dns-query"), | ||
| dnstt.WithPublicKey("405eb9e22d806e3a0a8e667c6665a321c8a6a35fa680ed814716a66d7ad84977"), | ||
| ) | ||
| require.NoError(t, err) | ||
| dnsTunnel3, err := dnstt.NewDNSTT( | ||
| dnstt.WithTunnelDomain("t.iantem.io"), | ||
| dnstt.WithDoH("https://dns.google/dns-query"), | ||
| dnstt.WithPublicKey("405eb9e22d806e3a0a8e667c6665a321c8a6a35fa680ed814716a66d7ad84977"), | ||
| ) | ||
| require.NoError(t, err) | ||
| dnsTunnel4, err := dnstt.NewDNSTT( | ||
| dnstt.WithTunnelDomain("t.iantem.io"), | ||
| dnstt.WithDoT("dns.quad9.net:853"), | ||
| dnstt.WithPublicKey("405eb9e22d806e3a0a8e667c6665a321c8a6a35fa680ed814716a66d7ad84977"), | ||
| ) | ||
| require.NoError(t, err) | ||
|
|
||
| return kindling.NewKindling( | ||
| "radiance", | ||
| kindling.WithPanicListener(reporting.PanicListener), | ||
| kindling.WithLogWriter(logger), | ||
| kindling.WithDNSTunnel(cli), | ||
| kindling.WithDNSTunnel(dnsTunnel2), | ||
| kindling.WithDNSTunnel(dnsTunnel3), | ||
| kindling.WithDNSTunnel(dnsTunnel4), | ||
| ) | ||
| }, | ||
| assert: func(t *testing.T, err error) { | ||
| assert.NoError(t, err) | ||
| }, | ||
| }, | ||
| { | ||
| name: "AMP Kindling", | ||
| description: "amp testing", | ||
| userID: userID, | ||
| locale: "en-US", | ||
| email: email, | ||
| country: "BR", | ||
| setup: func( | ||
| ctx context.Context, | ||
| t *testing.T, | ||
| dataDir string, | ||
| logger *slogWriter, | ||
| ) kindling.Kindling { | ||
| ampClient, err := fronted.NewAMPClient(ctx, logger, ampPublicKey) | ||
| require.NoError(t, err) | ||
|
|
||
| return kindling.NewKindling( | ||
| "radiance", | ||
| kindling.WithLogWriter(logger), | ||
| kindling.WithAMPCache(ampClient), | ||
| ) | ||
| }, | ||
| assert: func(t *testing.T, err error) { | ||
| assert.NoError(t, err) | ||
| }, | ||
| }, | ||
| } | ||
| for _, tc := range tests { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| dataDir := t.TempDir() | ||
| logDir := t.TempDir() | ||
| require.NoError(t, common.Init(dataDir, logDir, "TRACE")) | ||
| // create a txt file in log dir with random content with 1mb size | ||
| // ~1MB payload | ||
| const size = 0.007 * 1000000 | ||
| // Base64 inflates: 3 bytes → 4 chars | ||
| raw := make([]byte, size*3/4+3) // +3 to avoid truncation issues | ||
|
|
||
| _, err := rand.Read(raw) | ||
| require.NoError(t, err) | ||
|
|
||
| s := base64.RawURLEncoding.EncodeToString(raw) | ||
| s = s[:size] // exact length | ||
| require.NoError(t, os.WriteFile(logDir+"/largefile.txt", []byte(s), 0644)) | ||
|
|
||
| kindlingLogger := &slogWriter{Logger: slog.Default()} | ||
|
|
||
| ctx, cancel := context.WithCancel(context.Background()) | ||
| defer cancel() | ||
|
|
||
| k := tc.setup(ctx, t, dataDir, kindlingLogger) | ||
|
|
||
| httpClientWithTimeout := k.NewHTTPClient() | ||
| httpClientWithTimeout.Timeout = common.DefaultHTTPTimeout | ||
|
|
||
| reporter, err := issue.NewIssueReporter( | ||
| httpClientWithTimeout, | ||
| common.NewUserConfig(tc.userID, dataDir, tc.locale), | ||
| ) | ||
| require.NoError(t, err) | ||
|
|
||
| t.Run("reporting issue should work", func(t *testing.T) { | ||
| tc.assert(t, reporter.Report( | ||
| context.Background(), | ||
| issue.IssueReport{ | ||
| Type: "Other", | ||
| Description: tc.description, | ||
| Device: "test", | ||
| Model: "test", | ||
| Attachments: []*issue.Attachment{ | ||
| &issue.Attachment{ | ||
| Name: "Hello.txt", | ||
| Data: []byte("hello world"), | ||
| }, | ||
| }, | ||
| }, | ||
| tc.email, | ||
| tc.country, | ||
| )) | ||
| }) | ||
| }) | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.