Exploit databaseDownload repository ZIP
GH-e76a3d3d0be61d55e6620c59c6a75b15
cumakurt/php2shell-scan
Sources for CVE-2026-109618
412 sourcesPreferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source
Repository files3
cumakurt/php2shell-scanRevision 7f4ea41c2e62
Files from this repository share one source choice. Supporting files may cover other vulnerabilities.
internal/httpx/client_test.go
Go · 3,914 bytes// SPDX-License-Identifier: GPL-3.0-or-later
// Copyright (C) 2026 Cuma KURT <[email protected]>
//
// php2shell-scan is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
// Software Foundation, either version 3 of the License, or (at your option) any
// later version. It is distributed WITHOUT ANY WARRANTY; see the LICENSE file
// for the full text.
package httpx
import (
"context"
"net/http"
"net/http/httptest"
"sync/atomic"
"testing"
"time"
)
func TestCustomHeadersAndBasicAuth(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Header.Get("Authorization") != "Basic dXNlcjpwYXNz" {
t.Errorf("unexpected Authorization header: %q", r.Header.Get("Authorization"))
}
if r.Header.Get("X-Api-Key") != "secret-value" {
t.Errorf("missing custom header")
}
_, _ = w.Write([]byte("ok"))
}))
defer srv.Close()
c := New(Options{
Timeout: 2 * time.Second,
Headers: map[string]string{"X-Api-Key": "secret-value"},
BasicAuthUser: "user",
BasicAuthPassword: "pass",
})
if _, err := c.Get(context.Background(), srv.URL); err != nil {
t.Fatal(err)
}
}
func TestRetryOnTransientStatus(t *testing.T) {
var hits int32
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if atomic.AddInt32(&hits, 1) < 3 {
w.WriteHeader(http.StatusServiceUnavailable)
return
}
_, _ = w.Write([]byte("recovered"))
}))
defer srv.Close()
c := New(Options{
Timeout: 2 * time.Second,
MaxAttempts: 3,
RetryBaseDelay: time.Millisecond,
})
resp, err := c.Get(context.Background(), srv.URL)
if err != nil {
t.Fatal(err)
}
if resp.Status != http.StatusOK {
t.Fatalf("expected recovery, got %d", resp.Status)
}
if got := atomic.LoadInt32(&hits); got != 3 {
t.Errorf("expected 3 attempts, got %d", got)
}
}
func TestNoRetryOnClientError(t *testing.T) {
var hits int32
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
atomic.AddInt32(&hits, 1)
w.WriteHeader(http.StatusNotFound)
}))
defer srv.Close()
c := New(Options{Timeout: time.Second, MaxAttempts: 3, RetryBaseDelay: time.Millisecond})
if _, err := c.Get(context.Background(), srv.URL); err != nil {
t.Fatal(err)
}
if got := atomic.LoadInt32(&hits); got != 1 {
t.Errorf("404 must not be retried, got %d attempts", got)
}
}
func TestPostIsNotRetried(t *testing.T) {
var hits int32
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
atomic.AddInt32(&hits, 1)
w.WriteHeader(http.StatusServiceUnavailable)
}))
defer srv.Close()
c := New(Options{Timeout: time.Second, MaxAttempts: 3, RetryBaseDelay: time.Millisecond})
if _, err := c.PostForm(context.Background(), srv.URL, nil); err != nil {
t.Fatal(err)
}
if got := atomic.LoadInt32(&hits); got != 1 {
t.Errorf("POST must not be retried, got %d attempts", got)
}
}
func TestRequestBudget(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte("ok"))
}))
defer srv.Close()
c := New(Options{Timeout: time.Second, MaxRequests: 2})
for i := 0; i < 2; i++ {
if _, err := c.Get(context.Background(), srv.URL); err != nil {
t.Fatalf("request %d should succeed: %v", i+1, err)
}
}
if _, err := c.Get(context.Background(), srv.URL); err == nil {
t.Fatal("expected the budget error on the third request")
}
if c.Requests() < 3 {
t.Errorf("request counter = %d, want at least 3", c.Requests())
}
}
func TestInvalidProxyURLIgnored(t *testing.T) {
// A malformed proxy must not panic; it falls back to the environment proxy.
c := New(Options{Timeout: time.Second, ProxyURL: "://bad"})
if c == nil {
t.Fatal("client must still be constructed")
}
}