<commit_before><commit_msg>add tests<commit_after>package digest_auth_client

import "testing"

func TestHash(t *testing.T) {
	testCases := []struct {
		name      string
		algorithm string
		expRes    string
	}{
		{
			name:      "empty algorithm",
			algorithm: "",
			expRes:    "1a79a4d60de6718e8e5b326e338ae533",
		},
		{
			name:      "MD5 algorithm",
			algorithm: "MD5",
			expRes:    "1a79a4d60de6718e8e5b326e338ae533",
		},
		{
			name:      "MD5-sess algorithm",
			algorithm: "MD5",
			expRes:    "1a79a4d60de6718e8e5b326e338ae533",
		},
		{
			name:      "SHA256 algorithm",
			algorithm: "SHA-256",
			expRes:    "50d858e0985ecc7f60418aaf0cc5ab587f42c2570a884095a9e8ccacd0f6545c",
		},
		{
			name:      "SHA256-sess algorithm",
			algorithm: "SHA-256",
			expRes:    "50d858e0985ecc7f60418aaf0cc5ab587f42c2570a884095a9e8ccacd0f6545c",
		},
		//{
		//	name:      "md5 algorithm will panic",
		//	algorithm: "md5",
		//	expRes:    "1a79a4d60de6718e8e5b326e338ae533",
		//},
		//{
		//	name:      "unknown algorithm will panic",
		//	algorithm: "unknown",
		//	expRes:    "",
		//},
	}

	for _, tc := range testCases {
		t.Run(tc.name, func(t *testing.T) {
			ah := &authorization{Algorithm: tc.algorithm}
			res := ah.hash("example")
			if res != tc.expRes {
				t.Errorf("got: %q, want: %q", res, tc.expRes)
			}
		})
	}
}

func TestComputeA1(t *testing.T) {
	testCases := []struct {
		name      string
		algorithm string
		expRes    string
	}{
		{
			name:      "empty algorithm",
			algorithm: "",
			expRes:    "username:realm:secret",
		},
		{
			name:      "MD5 algorithm",
			algorithm: "MD5",
			expRes:    "username:realm:secret",
		},
		{
			name:      "MD5-sess algorithm",
			algorithm: "MD5",
			expRes:    "username:realm:secret",
		},
		{
			name:      "SHA256 algorithm",
			algorithm: "SHA-256",
			expRes:    "username:realm:secret",
		},
		{
			name:      "SHA256-sess algorithm",
			algorithm: "SHA-256",
			expRes:    "username:realm:secret",
		},
		{
			name:      "md5 algorithm",
			algorithm: "md5",
			expRes:    "",
		},
		{
			name:      "unknown algorithm",
			algorithm: "unknown",
			expRes:    "",
		},
	}

	for _, tc := range testCases {
		t.Run(tc.name, func(t *testing.T) {
			dr := &DigestRequest{Password: "<PASSWORD>"}
			ah := &authorization{
				Algorithm: tc.algorithm,
				Nonce:     "nonce",
				Cnonce:    "cnonce",
				Username:  "username",
				Realm:     "realm",
			}
			res := ah.computeA1(dr)
			if res != tc.expRes {
				t.Errorf("got: %q, want: %q", res, tc.expRes)
			}
		})
	}
}

func TestComputeA2(t *testing.T) {
	testCases := []struct {
		name       string
		qop        string
		expRes     string
		expAuthQop string
	}{
		{
			name:       "empty qop",
			qop:        "",
			expRes:     "method:uri",
			expAuthQop: "auth",
		},
		{
			name:       "qop is auth",
			qop:        "auth",
			expRes:     "method:uri",
			expAuthQop: "auth",
		},
		{
			name:       "qop is auth-int",
			qop:        "qop is auth-int",
			expRes:     "method:uri:841a2d689ad86bd1611447453c22c6fc",
			expAuthQop: "auth-int",
		},
	}

	for _, tc := range testCases {
		t.Run(tc.name, func(t *testing.T) {
			dr := &DigestRequest{
				Method: "method",
				Body:   "body",
				Wa: &wwwAuthenticate{
					Qop: tc.qop,
				},
			}
			ah := &authorization{
				Algorithm: "MD5",
				Nonce:     "nonce",
				Cnonce:    "cnonce",
				Username:  "username",
				Realm:     "realm",
				URI:       "uri",
				Qop:       tc.qop,
			}
			res := ah.computeA2(dr)
			if res != tc.expRes {
				t.Errorf("wrong result, got: %q, want: %q", res, tc.expRes)
			}
			if ah.Qop != tc.expAuthQop {
				t.Errorf("wrong qop, got: %q, want: %q", ah.Qop, tc.expAuthQop)
			}
		})
	}
}
{'fraction_non_alphanumeric': 0.1610466684650661, 'fraction_numerical': 0.060695980577286215, 'mean_word_length': 2.364791288566243, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3585330', 'n_tokens_mistral': 1885, 'n_tokens_neox': 1540, 'n_words': 278}