Skip to content
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

g3proxy: delete outdated ci tests #380

Merged
merged 7 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@ jobs:
image: ghcr.io/psf/httpbin:0.10.2
ports:
- 80:8080
fluent-bit:
image: ghcr.io/fluent/fluent-bit:latest
ports:
- '24224:24224/tcp'
steps:
- name: Checkout sources
uses: actions/checkout@v4
Expand All @@ -93,18 +89,33 @@ jobs:
- name: Install binutils
run: |
cargo install cargo-binutils
- name: Install netcat-openbsd
run: |
sudo apt-get install netcat-openbsd
- name: Listen StatsD port
run: |
nc -u -l -k 127.0.0.1 8125 >/dev/null &
- name: Install fluent-bit
run: |
sudo curl https://raw.githubusercontent.com/fluent/fluent-bit/master/install.sh | sh
- name: Install fluent-bit.conf
run: |
sudo cp ${{ github.workspace }}/scripts/coverage/g3proxy/fluent-bit.conf /etc/fluent-bit/fluent-bit.conf
- name: Start fluent-bit
run: |
sudo systemctl start fluent-bit
- name: Install dnsmasq
run: |
sudo apt-get install dnsmasq-base
- name: Backup /etc/resolv.conf
run: |
sudo cp /etc/resolv.conf /etc/resolv.conf.backup
- name: Run dnsmasq
run: |
sudo dnsmasq --local-service -C ${{ github.workspace }}/scripts/coverage/g3proxy/dnsmasq.conf
- name: Edit /etc/resolv.conf
run: |
echo "nameserver 127.0.0.1" | sudo tee /etc/resolv.conf
- name: Run dnsmasq
run: |
sudo dnsmasq --local-service -C ${{ github.workspace }}/scripts/coverage/g3proxy/dnsmasq.conf
- name: run unit test
run: |
./scripts/coverage/g3proxy.sh
Expand Down
21 changes: 18 additions & 3 deletions g3proxy/doc/configuration/user_group/source.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ lua

Fetch users through local lua script.

The following vars will be defined when running the script:

* __file__

This will be the absolute path of the script file

.. versionadded:: 1.11.0

The return value of the script should be the json encoded string of all dynamic users.

.. note::

Environment variable `LUA_PATH`_ and `LUA_CPATH`_ can be set to include more lua module files.
Expand All @@ -51,9 +61,6 @@ Fetch users through local lua script.
.. _LUA_PATH: https://www.lua.org/manual/5.1/manual.html#pdf-package.path
.. _LUA_CPATH: https://www.lua.org/manual/5.1/manual.html#pdf-package.cpath


The return value of the script should be the json encoded string of all dynamic users.

The keys used in *map* format are:

* cache_file
Expand Down Expand Up @@ -136,6 +143,14 @@ python

Fetch users through local python script.

The following vars will be defined when running the script:

* __file__

This will be the absolute path of the script file

.. versionadded:: 1.11.0

The keys used in *map* format are:

* cache_file
Expand Down
8 changes: 3 additions & 5 deletions g3proxy/src/auth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,9 @@ impl UserGroup {
return Some((Arc::clone(user), UserType::Static));
}

if self.config.dynamic_source.is_some() {
let dynamic_users = self.dynamic_users.load();
if let Some(user) = dynamic_users.get(username) {
return Some((Arc::clone(user), UserType::Dynamic));
}
let dynamic_users = self.dynamic_users.load();
if let Some(user) = dynamic_users.get(username) {
return Some((Arc::clone(user), UserType::Dynamic));
}

self.get_anonymous_user()
Expand Down
32 changes: 32 additions & 0 deletions g3proxy/src/auth/source/lua.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ use mlua::{Function, Lua, Value};
use crate::config::auth::source::lua::UserDynamicLuaSource;
use crate::config::auth::UserConfig;

const LUA_GLOBAL_VAR_FILE: &str = "__file__";

pub(super) async fn fetch_records(
source: &Arc<UserDynamicLuaSource>,
cache: &Path,
Expand Down Expand Up @@ -130,6 +132,16 @@ async fn call_lua_fetch(script: PathBuf) -> anyhow::Result<String> {

tokio::task::spawn_blocking(move || {
let lua = unsafe { Lua::unsafe_new() };
let globals = lua.globals();
globals
.set(LUA_GLOBAL_VAR_FILE, script.display().to_string())
.map_err(|e| {
anyhow!(
"failed to set {} to {}: {e}",
LUA_GLOBAL_VAR_FILE,
script.display()
)
})?;
let code = lua.load(&code);
code.eval::<String>()
.map_err(|e| anyhow!("failed to run lua fetch script {}: {e}", script.display()))
Expand All @@ -148,6 +160,16 @@ async fn call_lua_report_ok(script: PathBuf) -> anyhow::Result<()> {

tokio::task::spawn_blocking(move || {
let lua = unsafe { Lua::unsafe_new() };
let globals = lua.globals();
globals
.set(LUA_GLOBAL_VAR_FILE, script.display().to_string())
.map_err(|e| {
anyhow!(
"failed to set {} to {}: {e}",
LUA_GLOBAL_VAR_FILE,
script.display()
)
})?;
lua.load(&code)
.exec()
.map_err(|e| anyhow!("failed to load lua report script {}: {e}", script.display()))?;
Expand Down Expand Up @@ -175,6 +197,16 @@ async fn call_lua_report_err(script: PathBuf, e: String) -> anyhow::Result<()> {

tokio::task::spawn_blocking(move || {
let lua = unsafe { Lua::unsafe_new() };
let globals = lua.globals();
globals
.set(LUA_GLOBAL_VAR_FILE, script.display().to_string())
.map_err(|e| {
anyhow!(
"failed to set {} to {}: {e}",
LUA_GLOBAL_VAR_FILE,
script.display()
)
})?;
lua.load(&code)
.exec()
.map_err(|e| anyhow!("failed to load lua report script {}: {e}", script.display()))?;
Expand Down
26 changes: 26 additions & 0 deletions g3proxy/src/auth/source/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ const FN_NAME_FETCH_USERS: &str = "fetch_users";
const FN_NAME_REPORT_OK: &str = "report_ok";
const FN_NAME_REPORT_ERR: &str = "report_err";

const VAR_NAME_FILE: &str = "__file__";

pub(super) async fn fetch_records(
source: &Arc<UserDynamicPythonSource>,
cache: &Path,
Expand Down Expand Up @@ -142,6 +144,14 @@ async fn call_python_fetch(script: PathBuf) -> anyhow::Result<String> {
script.display(),
)
})?;
code.setattr(VAR_NAME_FILE, script.display().to_string())
.map_err(|e| {
anyhow!(
"failed to set {} to {}: {e}",
VAR_NAME_FILE,
script.display()
)
})?;

let fetch_users = code.getattr(FN_NAME_FETCH_USERS).map_err(|e| {
anyhow!(
Expand Down Expand Up @@ -190,6 +200,14 @@ async fn call_python_report_ok(script: PathBuf) -> anyhow::Result<()> {
script.display(),
)
})?;
code.setattr(VAR_NAME_FILE, script.display().to_string())
.map_err(|e| {
anyhow!(
"failed to set {} to {}: {e}",
VAR_NAME_FILE,
script.display()
)
})?;

if let Ok(report_ok) = code.getattr(FN_NAME_REPORT_OK) {
report_ok.call0().map_err(|e| {
Expand Down Expand Up @@ -224,6 +242,14 @@ async fn call_python_report_err(script: PathBuf, e: String) -> anyhow::Result<()
script.display(),
)
})?;
code.setattr(VAR_NAME_FILE, script.display().to_string())
.map_err(|e| {
anyhow!(
"failed to set {} to {}: {e}",
VAR_NAME_FILE,
script.display()
)
})?;

if let Ok(report_ok) = code.getattr(FN_NAME_REPORT_ERR) {
let tup = PyTuple::new(py, [e])
Expand Down
9 changes: 9 additions & 0 deletions g3proxy/utils/lua/src/cmd_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ pub fn run(lua: &Lua, args: &ArgMatches) -> anyhow::Result<()> {
let script = args
.get_one::<PathBuf>(COMMAND_ARG_SCRIPT)
.ok_or_else(|| anyhow!("no script file to run"))?;
let absolute_path = if !script.is_absolute() {
let mut cur_dir = std::env::current_dir()?;
cur_dir.push(script);
cur_dir
} else {
script.to_path_buf()
};

let verbose_level = args
.get_one::<u8>(COMMAND_ARG_VERBOSE)
Expand All @@ -59,6 +66,8 @@ pub fn run(lua: &Lua, args: &ArgMatches) -> anyhow::Result<()> {
let code = std::fs::read_to_string(script)
.map_err(|e| anyhow!("failed to read script file {}: {e:?}", script.display()))?;

let globals = lua.globals();
globals.set("__file__", absolute_path.display().to_string())?;
let code = lua.load(&code);

if verbose_level > 1 {
Expand Down
1 change: 1 addition & 0 deletions scripts/coverage/g3proxy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ do
sleep 2

[ -f "${dir}/testcases.sh" ] || continue
TESTCASE_DIR=${dir}
. "${dir}/testcases.sh"

g3proxy_ctl offline
Expand Down
4 changes: 4 additions & 0 deletions scripts/coverage/g3proxy/0000_all_resolver/g3proxy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

log: discard

stat:
target:
udp: 127.0.0.1:8125

resolver:
- name: cares1
type: c-ares
Expand Down
4 changes: 4 additions & 0 deletions scripts/coverage/g3proxy/0001_base_http_proxy/g3proxy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

log: fluentd

stat:
target:
udp: 127.0.0.1:8125

resolver:
- name: default
type: c-ares
Expand Down
4 changes: 4 additions & 0 deletions scripts/coverage/g3proxy/0002_base_socks_proxy/g3proxy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

log: syslog

stat:
target:
udp: 127.0.0.1:8125

resolver:
- name: default
type: c-ares
Expand Down
4 changes: 4 additions & 0 deletions scripts/coverage/g3proxy/0003_base_tcp_stream/g3proxy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

log: stdout

stat:
target:
udp: 127.0.0.1:8125

resolver:
- name: default
type: c-ares
Expand Down
4 changes: 4 additions & 0 deletions scripts/coverage/g3proxy/0004_base_http_gateway/g3proxy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

log: journal

stat:
target:
udp: 127.0.0.1:8125

resolver:
- name: default
type: c-ares
Expand Down
4 changes: 4 additions & 0 deletions scripts/coverage/g3proxy/0005_transparent_proxy/g3proxy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

log: journal

stat:
target:
udp: 127.0.0.1:8125

resolver:
- name: default
type: c-ares
Expand Down
4 changes: 4 additions & 0 deletions scripts/coverage/g3proxy/0006_chain_http_proxy/g3proxy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

log: journal

stat:
target:
udp: 127.0.0.1:8125

resolver:
- name: cares1
type: c-ares
Expand Down
4 changes: 4 additions & 0 deletions scripts/coverage/g3proxy/0007_chain_socks_proxy/g3proxy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

log: syslog

stat:
target:
udp: 127.0.0.1:8125

resolver:
- name: cares1
type: c-ares
Expand Down
4 changes: 4 additions & 0 deletions scripts/coverage/g3proxy/0008_base_user_auth/g3proxy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

log: journal

stat:
target:
udp: 127.0.0.1:8125

resolver:
- name: default
type: c-ares
Expand Down
4 changes: 4 additions & 0 deletions scripts/coverage/g3proxy/0009_anonymous_user/g3proxy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

log: journal

stat:
target:
udp: 127.0.0.1:8125

resolver:
- name: default
type: c-ares
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

log: journal

stat:
target:
udp: 127.0.0.1:8125

resolver:
- name: default
type: c-ares
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

log: journal

stat:
target:
udp: 127.0.0.1:8125

resolver:
- name: default
type: c-ares
Expand Down
Loading
Loading