mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 06:27:05 +00:00
Only log on failing cases in auth integration test
This commit is contained in:
parent
00ca7352ee
commit
9ae18cc96e
@ -327,7 +327,6 @@ func TestAuthModeAlwaysAllow(t *testing.T) {
|
|||||||
previousResourceVersion := make(map[string]float64)
|
previousResourceVersion := make(map[string]float64)
|
||||||
|
|
||||||
for _, r := range getTestRequests() {
|
for _, r := range getTestRequests() {
|
||||||
t.Logf("case %v", r)
|
|
||||||
var bodyStr string
|
var bodyStr string
|
||||||
if r.body != "" {
|
if r.body != "" {
|
||||||
sub := ""
|
sub := ""
|
||||||
@ -344,16 +343,19 @@ func TestAuthModeAlwaysAllow(t *testing.T) {
|
|||||||
bodyBytes := bytes.NewReader([]byte(bodyStr))
|
bodyBytes := bytes.NewReader([]byte(bodyStr))
|
||||||
req, err := http.NewRequest(r.verb, s.URL+r.URL, bodyBytes)
|
req, err := http.NewRequest(r.verb, s.URL+r.URL, bodyBytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
t.Logf("case %v", r)
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
func() {
|
func() {
|
||||||
resp, err := transport.RoundTrip(req)
|
resp, err := transport.RoundTrip(req)
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
t.Logf("case %v", r)
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
b, _ := ioutil.ReadAll(resp.Body)
|
b, _ := ioutil.ReadAll(resp.Body)
|
||||||
if _, ok := r.statusCodes[resp.StatusCode]; !ok {
|
if _, ok := r.statusCodes[resp.StatusCode]; !ok {
|
||||||
|
t.Logf("case %v", r)
|
||||||
t.Errorf("Expected status one of %v, but got %v", r.statusCodes, resp.StatusCode)
|
t.Errorf("Expected status one of %v, but got %v", r.statusCodes, resp.StatusCode)
|
||||||
t.Errorf("Body: %v", string(b))
|
t.Errorf("Body: %v", string(b))
|
||||||
} else {
|
} else {
|
||||||
@ -427,19 +429,21 @@ func TestAuthModeAlwaysDeny(t *testing.T) {
|
|||||||
transport := http.DefaultTransport
|
transport := http.DefaultTransport
|
||||||
|
|
||||||
for _, r := range getTestRequests() {
|
for _, r := range getTestRequests() {
|
||||||
t.Logf("case %v", r)
|
|
||||||
bodyBytes := bytes.NewReader([]byte(r.body))
|
bodyBytes := bytes.NewReader([]byte(r.body))
|
||||||
req, err := http.NewRequest(r.verb, s.URL+r.URL, bodyBytes)
|
req, err := http.NewRequest(r.verb, s.URL+r.URL, bodyBytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
t.Logf("case %v", r)
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
func() {
|
func() {
|
||||||
resp, err := transport.RoundTrip(req)
|
resp, err := transport.RoundTrip(req)
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
t.Logf("case %v", r)
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
if resp.StatusCode != http.StatusForbidden {
|
if resp.StatusCode != http.StatusForbidden {
|
||||||
|
t.Logf("case %v", r)
|
||||||
t.Errorf("Expected status Forbidden but got status %v", resp.Status)
|
t.Errorf("Expected status Forbidden but got status %v", resp.Status)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
@ -496,7 +500,6 @@ func TestAliceNotForbiddenOrUnauthorized(t *testing.T) {
|
|||||||
|
|
||||||
for _, r := range getTestRequests() {
|
for _, r := range getTestRequests() {
|
||||||
token := AliceToken
|
token := AliceToken
|
||||||
t.Logf("case %v", r)
|
|
||||||
var bodyStr string
|
var bodyStr string
|
||||||
if r.body != "" {
|
if r.body != "" {
|
||||||
sub := ""
|
sub := ""
|
||||||
@ -521,10 +524,12 @@ func TestAliceNotForbiddenOrUnauthorized(t *testing.T) {
|
|||||||
resp, err := transport.RoundTrip(req)
|
resp, err := transport.RoundTrip(req)
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
t.Logf("case %v", r)
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
b, _ := ioutil.ReadAll(resp.Body)
|
b, _ := ioutil.ReadAll(resp.Body)
|
||||||
if _, ok := r.statusCodes[resp.StatusCode]; !ok {
|
if _, ok := r.statusCodes[resp.StatusCode]; !ok {
|
||||||
|
t.Logf("case %v", r)
|
||||||
t.Errorf("Expected status one of %v, but got %v", r.statusCodes, resp.StatusCode)
|
t.Errorf("Expected status one of %v, but got %v", r.statusCodes, resp.StatusCode)
|
||||||
t.Errorf("Body: %v", string(b))
|
t.Errorf("Body: %v", string(b))
|
||||||
} else {
|
} else {
|
||||||
@ -580,7 +585,6 @@ func TestBobIsForbidden(t *testing.T) {
|
|||||||
|
|
||||||
for _, r := range getTestRequests() {
|
for _, r := range getTestRequests() {
|
||||||
token := BobToken
|
token := BobToken
|
||||||
t.Logf("case %v", r)
|
|
||||||
bodyBytes := bytes.NewReader([]byte(r.body))
|
bodyBytes := bytes.NewReader([]byte(r.body))
|
||||||
req, err := http.NewRequest(r.verb, s.URL+r.URL, bodyBytes)
|
req, err := http.NewRequest(r.verb, s.URL+r.URL, bodyBytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -592,10 +596,12 @@ func TestBobIsForbidden(t *testing.T) {
|
|||||||
resp, err := transport.RoundTrip(req)
|
resp, err := transport.RoundTrip(req)
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
t.Logf("case %v", r)
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
// Expect all of bob's actions to return Forbidden
|
// Expect all of bob's actions to return Forbidden
|
||||||
if resp.StatusCode != http.StatusForbidden {
|
if resp.StatusCode != http.StatusForbidden {
|
||||||
|
t.Logf("case %v", r)
|
||||||
t.Errorf("Expected not status Forbidden, but got %s", resp.Status)
|
t.Errorf("Expected not status Forbidden, but got %s", resp.Status)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
@ -641,7 +647,6 @@ func TestUnknownUserIsUnauthorized(t *testing.T) {
|
|||||||
|
|
||||||
for _, r := range getTestRequests() {
|
for _, r := range getTestRequests() {
|
||||||
token := UnknownToken
|
token := UnknownToken
|
||||||
t.Logf("case %v", r)
|
|
||||||
bodyBytes := bytes.NewReader([]byte(r.body))
|
bodyBytes := bytes.NewReader([]byte(r.body))
|
||||||
req, err := http.NewRequest(r.verb, s.URL+r.URL, bodyBytes)
|
req, err := http.NewRequest(r.verb, s.URL+r.URL, bodyBytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -652,10 +657,12 @@ func TestUnknownUserIsUnauthorized(t *testing.T) {
|
|||||||
resp, err := transport.RoundTrip(req)
|
resp, err := transport.RoundTrip(req)
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
t.Logf("case %v", r)
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
// Expect all of unauthenticated user's request to be "Unauthorized"
|
// Expect all of unauthenticated user's request to be "Unauthorized"
|
||||||
if resp.StatusCode != http.StatusUnauthorized {
|
if resp.StatusCode != http.StatusUnauthorized {
|
||||||
|
t.Logf("case %v", r)
|
||||||
t.Errorf("Expected status %v, but got %v", http.StatusUnauthorized, resp.StatusCode)
|
t.Errorf("Expected status %v, but got %v", http.StatusUnauthorized, resp.StatusCode)
|
||||||
b, _ := ioutil.ReadAll(resp.Body)
|
b, _ := ioutil.ReadAll(resp.Body)
|
||||||
t.Errorf("Body: %v", string(b))
|
t.Errorf("Body: %v", string(b))
|
||||||
@ -746,7 +753,6 @@ func TestNamespaceAuthorization(t *testing.T) {
|
|||||||
|
|
||||||
for _, r := range requests {
|
for _, r := range requests {
|
||||||
token := BobToken
|
token := BobToken
|
||||||
t.Logf("case %v", r)
|
|
||||||
var bodyStr string
|
var bodyStr string
|
||||||
if r.body != "" {
|
if r.body != "" {
|
||||||
sub := ""
|
sub := ""
|
||||||
@ -766,6 +772,7 @@ func TestNamespaceAuthorization(t *testing.T) {
|
|||||||
bodyBytes := bytes.NewReader([]byte(bodyStr))
|
bodyBytes := bytes.NewReader([]byte(bodyStr))
|
||||||
req, err := http.NewRequest(r.verb, s.URL+r.URL, bodyBytes)
|
req, err := http.NewRequest(r.verb, s.URL+r.URL, bodyBytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
t.Logf("case %v", r)
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token))
|
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token))
|
||||||
@ -773,10 +780,12 @@ func TestNamespaceAuthorization(t *testing.T) {
|
|||||||
resp, err := transport.RoundTrip(req)
|
resp, err := transport.RoundTrip(req)
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
t.Logf("case %v", r)
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
b, _ := ioutil.ReadAll(resp.Body)
|
b, _ := ioutil.ReadAll(resp.Body)
|
||||||
if _, ok := r.statusCodes[resp.StatusCode]; !ok {
|
if _, ok := r.statusCodes[resp.StatusCode]; !ok {
|
||||||
|
t.Logf("case %v", r)
|
||||||
t.Errorf("Expected status one of %v, but got %v", r.statusCodes, resp.StatusCode)
|
t.Errorf("Expected status one of %v, but got %v", r.statusCodes, resp.StatusCode)
|
||||||
t.Errorf("Body: %v", string(b))
|
t.Errorf("Body: %v", string(b))
|
||||||
} else {
|
} else {
|
||||||
@ -852,7 +861,6 @@ func TestKindAuthorization(t *testing.T) {
|
|||||||
|
|
||||||
for _, r := range requests {
|
for _, r := range requests {
|
||||||
token := BobToken
|
token := BobToken
|
||||||
t.Logf("case %v", r)
|
|
||||||
var bodyStr string
|
var bodyStr string
|
||||||
if r.body != "" {
|
if r.body != "" {
|
||||||
bodyStr = fmt.Sprintf(r.body, "")
|
bodyStr = fmt.Sprintf(r.body, "")
|
||||||
@ -867,6 +875,7 @@ func TestKindAuthorization(t *testing.T) {
|
|||||||
bodyBytes := bytes.NewReader([]byte(bodyStr))
|
bodyBytes := bytes.NewReader([]byte(bodyStr))
|
||||||
req, err := http.NewRequest(r.verb, s.URL+r.URL, bodyBytes)
|
req, err := http.NewRequest(r.verb, s.URL+r.URL, bodyBytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
t.Logf("case %v", r)
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token))
|
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token))
|
||||||
@ -874,10 +883,12 @@ func TestKindAuthorization(t *testing.T) {
|
|||||||
resp, err := transport.RoundTrip(req)
|
resp, err := transport.RoundTrip(req)
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
t.Logf("case %v", r)
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
b, _ := ioutil.ReadAll(resp.Body)
|
b, _ := ioutil.ReadAll(resp.Body)
|
||||||
if _, ok := r.statusCodes[resp.StatusCode]; !ok {
|
if _, ok := r.statusCodes[resp.StatusCode]; !ok {
|
||||||
|
t.Logf("case %v", r)
|
||||||
t.Errorf("Expected status one of %v, but got %v", r.statusCodes, resp.StatusCode)
|
t.Errorf("Expected status one of %v, but got %v", r.statusCodes, resp.StatusCode)
|
||||||
t.Errorf("Body: %v", string(b))
|
t.Errorf("Body: %v", string(b))
|
||||||
} else {
|
} else {
|
||||||
@ -946,7 +957,6 @@ func TestReadOnlyAuthorization(t *testing.T) {
|
|||||||
|
|
||||||
for _, r := range requests {
|
for _, r := range requests {
|
||||||
token := BobToken
|
token := BobToken
|
||||||
t.Logf("case %v", r)
|
|
||||||
bodyBytes := bytes.NewReader([]byte(r.body))
|
bodyBytes := bytes.NewReader([]byte(r.body))
|
||||||
req, err := http.NewRequest(r.verb, s.URL+r.URL, bodyBytes)
|
req, err := http.NewRequest(r.verb, s.URL+r.URL, bodyBytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -957,9 +967,11 @@ func TestReadOnlyAuthorization(t *testing.T) {
|
|||||||
resp, err := transport.RoundTrip(req)
|
resp, err := transport.RoundTrip(req)
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
t.Logf("case %v", r)
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
if _, ok := r.statusCodes[resp.StatusCode]; !ok {
|
if _, ok := r.statusCodes[resp.StatusCode]; !ok {
|
||||||
|
t.Logf("case %v", r)
|
||||||
t.Errorf("Expected status one of %v, but got %v", r.statusCodes, resp.StatusCode)
|
t.Errorf("Expected status one of %v, but got %v", r.statusCodes, resp.StatusCode)
|
||||||
b, _ := ioutil.ReadAll(resp.Body)
|
b, _ := ioutil.ReadAll(resp.Body)
|
||||||
t.Errorf("Body: %v", string(b))
|
t.Errorf("Body: %v", string(b))
|
||||||
|
Loading…
Reference in New Issue
Block a user