Skip to content

Commit de08716

Browse files
committed
deafult to anonymous auth when no credentials
1 parent 438e095 commit de08716

File tree

10 files changed

+5818
-5760
lines changed

10 files changed

+5818
-5760
lines changed

e2e/e2e_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,11 @@ var (
128128
// MatrixRuntimes for which runtime-specific tests should be run. Defaults
129129
// to all core language runtimes. Can be set with FUNC_E2E_MATRIX_RUNTIMES
130130
// MatrixRuntimes = []string{"go", "python", "node", "typescript", "rust", "quarkus", "springboot"}
131-
MatrixRuntimes = []string{"go", "python", "node", "typescript", "rust", "quarkus", "springboot"}
131+
MatrixRuntimes = []string{"quarkus", "springboot"}
132132

133133
// MatrixTemplates specifies the templates to check during matrix tests.
134134
// MatrixTemplates = []string{"http", "cloudevents"}
135-
MatrixTemplates = []string{"cloudevents"}
135+
MatrixTemplates = []string{"http", "cloudevents"}
136136

137137
// Plugin indicates func is being run as a plugin within Bin, and
138138
// the value of this argument is the subcommand. For example, when

generate/zz_filesystem_generated.go

Lines changed: 5686 additions & 5679 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hack/common.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ init() {
1919
}
2020

2121
find_executables() {
22-
KUBECTL=$(find_executable "kubectl")
23-
KIND=$(find_executable "kind")
24-
DAPR=$(find_executable "dapr")
25-
HELM=$(find_executable "helm")
26-
STERN=$(find_executable "stern")
27-
KN=$(find_executable "kn")
28-
JQ=$(find_executable "jq")
22+
KUBECTL=$(find_executable "kubectl" || true)
23+
KIND=$(find_executable "kind" || true)
24+
DAPR=$(find_executable "dapr" || true)
25+
HELM=$(find_executable "helm" || true)
26+
STERN=$(find_executable "stern" || true)
27+
KN=$(find_executable "kn" || true)
28+
JQ=$(find_executable "jq" || true)
2929
}
3030

3131
populate_environment() {

hack/dump-logs.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,14 @@ source "$(dirname "$(realpath "$0")")/common.sh"
2525
output_file="${1:-cluster_log.txt}"
2626

2727
echo "::group::cluster events" >> "$output_file"
28-
kubectl get events -A >> "$output_file" 2>&1
28+
"$KUBECTL" get events -A >> "$output_file" 2>&1
2929
echo "::endgroup::" >> "$output_file"
3030

3131
echo "::group::cluster containers logs" >> "$output_file"
32-
stern '.*' --all-namespaces --no-follow >> "$output_file" 2>&1
32+
if [[ -n "${STERN:-}" && -x "${STERN}" ]]; then
33+
"$STERN" '.*' --all-namespaces --no-follow >> "$output_file" 2>&1
34+
else
35+
echo "stern not available, skipping container logs" >> "$output_file" 2>&1
36+
fi
3337
echo "::endgroup::" >> "$output_file"
3438

hack/test-full.sh

Lines changed: 64 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,30 @@
11
#!/usr/bin/env bash
22

3-
# Licensed under the Apache License, Version 2.0 (the "License");
4-
# you may not use this file except in compliance with the License.
5-
# You may obtain a copy of the License at
3+
# This script runs unit, integration and e2e tests with all optional tests
4+
# enabled:
5+
# - Matrix (for each runtime/language/builder c. product)
6+
# - Podman
7+
# - Gitlab
8+
# - Pipelines
9+
# - etc.
610
#
7-
# https://www.apache.org/licenses/LICENSE-2.0
11+
# (See the environment variables which allow selective overriding.)
812
#
9-
# Unless required by applicable law or agreed to in writing, software
10-
# distributed under the License is distributed on an "AS IS" BASIS,
11-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-
# See the License for the specific language governing permissions and
13-
# limitations under the License.
14-
15-
#
16-
# Run full test suite with all features enabled
17-
# This script sets up the environment for comprehensive testing including
18-
# Podman, Tekton, GitLab, and matrix tests
19-
#
20-
# Cluster Setup:
21-
# This script defaults to running all of the optional tests. This requires
22-
# one install the toolchains for all core language runtimes, Podman,
23-
# and configure the cluster with:
24-
# hack/cluster.sh
25-
# hack/registry.sh
26-
# hack/git-server.sh
27-
# hack/gitlab.sh
13+
# This script presumes a local testing environment set up using the
14+
# helper scripts in ./hack and performs some precondition checks to ensure
15+
# resources are available for the features enabled (nonexhaustive).
16+
# hack/binaries.sh - Installs necessary binaries in ./hack/bin
17+
# hack/cluster.sh - Start test cluster with Knative Serving/Eventing
18+
# hack/registry.sh - Starts and configures a local container registry
19+
# hack/git-server.sh - Starts a git server in-cluster
20+
# hack/gitlab.sh - Installs GitLab in-cluster
2821

2922
set -o errexit
3023
set -o nounset
3124
set -o pipefail
3225

33-
# Determine script directory
34-
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
35-
PROJECT_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
36-
37-
# Generate a timestamp for use setting things which require uniqueness
38-
TIMESTAMP=$(date +%Y%m%d%H%M%S 2>/dev/null || date +%s 2>/dev/null || echo "$(date)")
39-
40-
# Set up PATH and KUBECONFIG
41-
export PATH="${PROJECT_ROOT}/hack/bin:${PATH}"
42-
export KUBECONFIG="${KUBECONFIG:-${PROJECT_ROOT}/hack/bin/kubeconfig.yaml}"
43-
44-
# Set up test environment variables
26+
# Enable Optional Tests
27+
# ---------------------
4528
# The defaults in the e2e test implementation are a bit more conservative.
4629
# Here we toggle on All The Things. Note that we still allow any settings
4730
# made explicitly in the current environment to take precidence; just setting
@@ -55,13 +38,34 @@ export GITLAB_TESTS_ENABLED="${GITLAB_TESTS_ENABLED:-1}"
5538
export GITLAB_HOSTNAME="${GITLAB_HOSTNAME:-gitlab.localtest.me}"
5639
export PAC_CONTROLLER_HOSTNAME="${PAC_CONTROLLER_HOSTNAME:-pac-ctr.localtest.me}"
5740

41+
42+
# Environment Setup
43+
# -------------------
44+
45+
# Determine script directory
46+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
47+
PROJECT_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
48+
49+
# Set up PATH and KUBECONFIG
50+
export PATH="${PROJECT_ROOT}/hack/bin:${PATH}"
51+
export KUBECONFIG="${KUBECONFIG:-${PROJECT_ROOT}/hack/bin/kubeconfig.yaml}"
52+
5853
# GitLab test configuration
5954
# This is the default set by ./hack/gitlab.sh, and is overridden in CI, and
6055
# a warning is issued that users should not only use ./hack/gitlab.sh for
6156
# configuring test cluster available locally, such as that created by
6257
# hack/cluster.sh
6358
export GITLAB_ROOT_PASSWORD="${GITLAB_ROOT_PASSWORD:-test-password-123}"
6459

60+
# Generate a timestamp for use setting things which require uniqueness
61+
TIMESTAMP=$(date +%Y%m%d%H%M%S 2>/dev/null || date +%s 2>/dev/null || echo "$(date)")
62+
63+
# Initialize coverage file
64+
echo "mode: atomic" > coverage.txt
65+
66+
# Precondition Checks
67+
# -------------------
68+
6569
# Check if binaries are installed
6670
if [ ! -d "${PROJECT_ROOT}/hack/bin" ]; then
6771
echo "ERROR: hack/bin directory not found!"
@@ -121,6 +125,9 @@ fi
121125
echo "✓ Prerequisites check passed"
122126
echo ""
123127

128+
# Podman Setup
129+
# -------------
130+
124131
# Check Podman service if Podman tests are enabled
125132
if [ "${FUNC_E2E_PODMAN}" = "true" ]; then
126133
# Check if Podman service is running
@@ -161,31 +168,36 @@ if [ "${FUNC_E2E_PODMAN}" = "true" ]; then
161168
export FUNC_E2E_PODMAN_HOST="unix://${PODMAN_SOCKET}"
162169
fi
163170
fi
164-
echo "Podman socket: ${FUNC_E2E_PODMAN_HOST}"
171+
echo "Podman socket: ${FUNC_E2E_PODMAN_HOST}"
165172
fi
166173

167-
# Initialize coverage file
168-
echo "mode: atomic" > coverage.txt
174+
# Unit and Integration Tests
175+
# --------------------------
169176

170-
# Run unit and integration tests together
171-
# echo ""
172-
# echo "Running unit and integration tests..."
173-
# go test -tags integration -timeout 60m -coverprofile=coverage-integration.txt ./... -v
174-
# tail -n +2 coverage-integration.txt >> coverage.txt
175-
# rm -f coverage-integration.text -run TestMetadata_Labels_Remove
177+
Run unit and integration tests together
178+
echo ""
179+
echo "Running unit and integration tests..."
180+
go test -tags integration -timeout 60m -coverprofile=coverage-integration.txt ./... -v
181+
tail -n +2 coverage-integration.txt >> coverage.txt
182+
rm -f coverage-integration.text -run TestMetadata_Labels_Remove
183+
184+
echo "✓ Unit and Integration tests completed successfully"
185+
186+
# E2E Tests
187+
# --------------------------
176188

177189
# Run E2E tests
178-
echo ""
179-
echo "Running E2E tests..."
180-
cd "${PROJECT_ROOT}/e2e"
181-
go test -tags e2e -timeout 120m -coverprofile=coverage-e2e.txt -coverpkg=../... -v -run TestMatrix_Deploy
190+
# echo ""
191+
# echo "Running E2E tests..."
192+
# cd "${PROJECT_ROOT}/e2e"
193+
# # go test -tags e2e -timeout 120m -coverprofile=coverage-e2e.txt -coverpkg=../... -v -run TestMatrix_Run
182194
# go test -tags e2e -timeout 120m -coverprofile=coverage-e2e.txt -coverpkg=../... -v
183-
tail -n +2 coverage-e2e.txt >> ../coverage.txt
184-
rm -f coverage-e2e.txt
195+
# tail -n +2 coverage-e2e.txt >> ../coverage.txt
196+
# rm -f coverage-e2e.txt
185197

186198
cd "${PROJECT_ROOT}"
187199
echo ""
188-
echo "Coverage report created: coverage.txt"
200+
echo "Coverage report created: coverage.txt"
189201

190202
echo ""
191-
echo "All tests completed successfully!"
203+
echo "All tests completed successfully"

pkg/oci/pusher.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,6 @@ func (p *Pusher) writeIndex(ctx context.Context, ref name.Reference, ii v1.Image
172172
if err != nil {
173173
return err
174174
}
175-
if a == nil {
176-
return errors.New("no authentication option provided")
177-
}
178175
oo = append(oo, a)
179176
}
180177

@@ -210,5 +207,6 @@ func (p *Pusher) authOption(ctx context.Context, creds Credentials) (remote.Opti
210207
return remote.WithAuth(&authn.Basic{Username: creds.Username, Password: creds.Password}), nil
211208
}
212209

213-
return nil, nil
210+
// Return anonymous auth when no credentials are provided (e.g., for localhost registries)
211+
return remote.WithAuth(authn.Anonymous), nil
214212
}

templates/rust/cloudevents/src/handler.rs

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,35 @@ pub async fn handle(
1111
) -> Result<Event, actix_web::Error> {
1212
info!("event: {}", event);
1313

14-
let input = match event.data() {
15-
Some(Data::Binary(v)) => from_slice(v)?,
16-
Some(Data::String(v)) => from_str(v)?,
17-
Some(Data::Json(v)) => v.to_owned(),
18-
None => json!({ "name": config.name }),
14+
// Extract message from event data, or use default
15+
let message = match event.data() {
16+
Some(Data::Binary(v)) => {
17+
let input: serde_json::Value = from_slice(v)?;
18+
input.get("message")
19+
.and_then(|v| v.as_str())
20+
.unwrap_or(&config.name)
21+
.to_string()
22+
},
23+
Some(Data::String(v)) => {
24+
let input: serde_json::Value = from_str(v)?;
25+
input.get("message")
26+
.and_then(|v| v.as_str())
27+
.unwrap_or(&config.name)
28+
.to_string()
29+
},
30+
Some(Data::Json(v)) => {
31+
v.get("message")
32+
.and_then(|v| v.as_str())
33+
.unwrap_or(&config.name)
34+
.to_string()
35+
},
36+
None => config.name.clone(),
1937
};
2038

2139
EventBuilderV10::from(event)
2240
.source("func://handler")
23-
.ty("func.example")
24-
.data("application/json", json!({ "hello": input["name"] }))
41+
.ty("func.echo")
42+
.data("application/json", json!({ "message": message }))
2543
.build()
2644
.map_err(ErrorInternalServerError)
2745
}
@@ -37,11 +55,11 @@ mod tests {
3755
#[actix_rt::test]
3856
async fn valid_input() {
3957
let mut input = Event::default();
40-
input.set_data("application/json", json!({"name": "bootsy"}));
58+
input.set_data("application/json", json!({"message": "test-echo"}));
4159
let resp = handle(input, config()).await;
4260
assert!(resp.is_ok());
4361
match resp.unwrap().data() {
44-
Some(Data::Json(output)) => assert_eq!("bootsy", output["hello"]),
62+
Some(Data::Json(output)) => assert_eq!("test-echo", output["message"]),
4563
_ => panic!(),
4664
}
4765
}
@@ -51,7 +69,7 @@ mod tests {
5169
let resp = handle(Event::default(), config()).await;
5270
assert!(resp.is_ok());
5371
match resp.unwrap().data() {
54-
Some(Data::Json(output)) => assert_eq!("world", output["hello"]),
72+
Some(Data::Json(output)) => assert_eq!("world", output["message"]),
5573
_ => panic!(),
5674
}
5775
}

templates/rust/http/src/handler.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@ use log::info;
66
pub async fn index(req: HttpRequest, config: Data<HandlerConfig>) -> HttpResponse {
77
info!("{:#?}", req);
88
if req.method() == Method::GET {
9-
HttpResponse::Ok().body(format!("Hello {}!\n", config.name))
9+
// Echo back the query string if present, otherwise return greeting
10+
let query = req.query_string();
11+
if !query.is_empty() {
12+
HttpResponse::Ok().body(query.to_string())
13+
} else {
14+
HttpResponse::Ok().body(format!("Hello {}!\n", config.name))
15+
}
1016
} else {
1117
HttpResponse::Ok().body(format!("Thanks {}!\n", config.name))
1218
}
@@ -32,6 +38,19 @@ mod tests {
3238
);
3339
}
3440

41+
#[actix_rt::test]
42+
async fn get_with_query() {
43+
let req = TestRequest::get()
44+
.uri("/?test=param&message=hello")
45+
.to_http_request();
46+
let resp = index(req, config()).await;
47+
assert_eq!(resp.status(), http::StatusCode::OK);
48+
assert_eq!(
49+
&Bytes::from("test=param&message=hello"),
50+
to_bytes(resp.into_body()).await.unwrap().as_ref()
51+
);
52+
}
53+
3554
#[actix_rt::test]
3655
async fn post() {
3756
let req = TestRequest::post().to_http_request();

templates/typescript/http/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ ${JSON.stringify(body)}
5050
}
5151
};
5252
} else {
53-
return {
54-
statusCode: 405,
53+
return {
54+
statusCode: 405,
5555
body: { error: 'Method not allowed' },
5656
headers: {
5757
'content-type': 'application/json'

templates/typescript/http/test/unit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ test('Unit: handles a valid request', async (t) => {
1414
};
1515

1616
// Invoke the function which should complete without error and echo the data
17-
const result = await handle({ log: { info: (_) => _ } } as Context, body);
17+
const result = await handle({ method: 'POST', log: { info: (_) => _ } } as Context, body);
1818
t.ok(result);
1919
t.equal(result.body, body);
2020
t.end();

0 commit comments

Comments
 (0)