/*
 * Copyright 2013 Couchbase, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.couchbase.mock.http;
import java.io.IOException;

import org.couchbase.mock.util.Base64;

/**
 *
 * @author mnunberg
 */
public class AuthContext {
    private String username;
    private String password;

    public AuthContext (String hdr) throws IOException {
        String[] parts = hdr.split(" ");
        if (parts.length != 2) {
            throw new IOException("Invalid auth header");
        }

        if (!parts[0].equals("Basic")) {
            throw new IOException("Non-Basic auth not supported");
        }

        String b64 = parts[1];

        parts = Base64.decode(b64).split(":");
        username = parts[0];
        password = parts[1];
    }

    public AuthContext () {
        username = "";
        password = "";
    }

    public String getUsername() {
        return username;
    }
    public String getPassword() {
        return password;
    }
}

@@ -1162,25 +1162,24 @@
 rts%5B1%5D;%0A
-%0A
         
 parts = 
@@ -1170,21 +1170,30 @@
         
-parts
+String decoded
  = Base6
@@ -1205,16 +1205,41 @@
 ode(b64)
+;%0A        parts = decoded
 .split(%22
@@ -1240,19 +1240,60 @@
 plit(%22:%22
+, 2
 );%0A
+%0A
+        if (parts.length == 2) %7B%0A    
         
@@ -1313,32 +1313,36 @@
 rts%5B0%5D;%0A        
+    
 password = parts
@@ -1342,24 +1342,127 @@
 = parts%5B1%5D;%0A
+        %7D else %7B%0A            throw new IOException(%22Don't know what to do with %22 + decoded);%0A        %7D%0A
     %7D%0A%0A    p

Fix user:pass handling in AuthContext