<commit_before>
'use strict';
require('should');
var www_authenticate = require('..')
  , parsers = require('../lib/parsers')
  ;

var CNONCE='0a4f113b'

describe( 'www-authenticate', function() {
  describe( 'www_authenticate()', function() {
    it( 'should be a function', function() {
      www_authenticate.should.be.a( 'function' );
    } );
    it( 'should return a function', function() {
      www_authenticate()
    } );
    it( 'should authenticate rfc2617 example', function(done) {
      var header_parser= www_authenticate("Mufasa","Circle Of Life",{cnonce:CNONCE})
      //...receive HTTP/1.1 401 Unauthorized
      // parse header['www-authenticate']:
      header_parser('Digest '+
                 'realm="<EMAIL>", '+
                 'qop="auth,auth-int", '+
                 'nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", '+
                 'opaque="5ccc069c403ebaf9f0171e9517f40e41"',
        function(err,authorizer) {
          if (err) throw err;
          var authorize= authorizer.authorize; //function to produce Authorization header
          // now, whenever you need to create an Authorization header:
          authorize("GET","/dir/index.html").should.equal(
                'Digest username="Mufasa", '+
                'realm="<EMAIL>", '+
                'nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", '+
                'uri="/dir/index.html", '+
                'qop=auth, '+
                'nc=00000001, '+
                'cnonce="'+CNONCE+'", '+
                'response="6629fae49393a05397450978507c4ef1", '+
                'opaque="5ccc069c403ebaf9f0171e9517f40e41"'
          );
          done();
        }
      );
    } );
    it( 'should increment nonce-count', function(done) {
      var header_parser= www_authenticate("Mufasa","Circle Of Life",{cnonce:CNONCE})
      header_parser('Digest '+
                 'realm="<EMAIL>", '+
                 'qop="auth,auth-int", '+
                 'nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", '+
                 'opaque="5ccc069c403ebaf9f0171e9517f40e41"',
        function(err,authorizer) {
          if (err) throw err;
          var authorize= authorizer.authorize;
          authorize("GET","/dir/index.html");
          authorize("GET","/dir/index.html").should.include('nc=00000002');
          done();
        }
      );
    } );
    it( 'should parse an Authentication_Info header', function(done) {
      var header_parser= www_authenticate("Mufasa","Circle Of Life",{cnonce:CNONCE})
      var parsed= new parsers.Authentication_Info(
                 'nextnonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", '+
                 'qop="auth,auth-int", '+
                 'rspauth="6629fae49393a05397450978507c4ef1", '+
                 'nc=00000001, '+
                 'cnonce="abc""def"'
              );
      parsed.should.not.have.property('err');
      var parms= parsed.parms;
      parms.should.have.property('nextnonce','dcd98b7102dd2f0e8b11d0f600bfb0c093');
      parms['nextnonce'].should.equal('dcd98b7102dd2f0e8b11d0f600bfb0c093');
      parms['qop'].should.equal('auth,auth-int');
      parms['rspauth'].should.equal('6629fae49393a05397450978507c4ef1');
      parms['nc'].should.equal('00000001');
      parms['cnonce'].should.equal('abc"def');  // double double quote properly parsed as single double quote
      done();
    } );
  } );
} );<commit_msg>Test parsing a quoted string that includes a comma.<commit_after>
'use strict';
require('should');
var www_authenticate = require('..')
  , parsers = require('../lib/parsers')
  ;

var CNONCE='0a4f113b'

describe( 'www-authenticate', function() {
  describe( 'www_authenticate()', function() {
    it( 'should be a function', function() {
      www_authenticate.should.be.a( 'function' );
    } );
    it( 'should return a function', function() {
      www_authenticate()
    } );
    it( 'should authenticate rfc2617 example', function(done) {
      var header_parser= www_authenticate("Mufasa","Circle Of Life",{cnonce:CNONCE})
      //...receive HTTP/1.1 401 Unauthorized
      // parse header['www-authenticate']:
      header_parser('Digest '+
                 'realm="<EMAIL>", '+
                 'qop="auth,auth-int", '+
                 'nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", '+
                 'opaque="5ccc069c403ebaf9f0171e9517f40e41"',
        function(err,authorizer) {
          if (err) throw err;
          var authorize= authorizer.authorize; //function to produce Authorization header
          // now, whenever you need to create an Authorization header:
          authorize("GET","/dir/index.html").should.equal(
                'Digest username="Mufasa", '+
                'realm="<EMAIL>", '+
                'nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", '+
                'uri="/dir/index.html", '+
                'qop=auth, '+
                'nc=00000001, '+
                'cnonce="'+CNONCE+'", '+
                'response="6629fae49393a05397450978507c4ef1", '+
                'opaque="5ccc069c403ebaf9f0171e9517f40e41"'
          );
          done();
        }
      );
    } );
    it( 'should increment nonce-count', function(done) {
      var header_parser= www_authenticate("Mufasa","Circle Of Life",{cnonce:CNONCE})
      header_parser('Digest '+
                 'realm="<EMAIL>", '+
                 'qop="auth,auth-int", '+
                 'nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", '+
                 'opaque="5ccc069c403ebaf9f0171e9517f40e41"',
        function(err,authorizer) {
          if (err) throw err;
          var authorize= authorizer.authorize;
          authorize("GET","/dir/index.html");
          authorize("GET","/dir/index.html").should.include('nc=00000002');
          done();
        }
      );
    } );
    it( 'should parse an Authentication_Info header', function(done) {
      var header_parser= www_authenticate("Mufasa","Circle Of Life",{cnonce:CNONCE})
      var parsed= new parsers.Authentication_Info(
                 'nextnonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", '+
                 'qop="auth,auth-int", '+
                 'rspauth="6629fae4<PASSWORD>a05397450978507c4ef1", '+
                 'nc=00000001, '+
                 'cnonce="abc""def"'
              );
      parsed.should.not.have.property('err');
      var parms= parsed.parms;
      parms.should.have.property('nextnonce','dcd98b7102dd2f0e8b11d0f600bfb0c093');
      parms['nextnonce'].should.equal('dcd98b7102dd2f0e8b11d0f600bfb0c093');
      parms['qop'].should.equal('auth,auth-int');
      parms['rspauth'].should.equal('<PASSWORD>');
      parms['nc'].should.equal('00000001');
      parms['cnonce'].should.equal('abc"def');  // double double quote properly parsed as single double quote
      done();
    } );
    it( 'should correctly parse a quoted string that includes a comma', function(done) {
      var header_parser= www_authenticate("Mufasa","Circle Of Life",{cnonce:CNONCE})
      var parsed= new parsers.Authentication_Info(
                 'nextnonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", '+
                 'qop="auth,auth-int", '+
                 'rspauth="<PASSWORD>", '+
                 'nc=00000001, '+
                 'cnonce="abc""d,ef"'
              );
      parsed.should.not.have.property('err');
      var parms= parsed.parms;
      parms.should.have.property('nextnonce','dcd98b7102dd2f0e8b11d0f600bfb0c093');
      parms['nextnonce'].should.equal('dcd98b7102dd2f0e8b11d0f600bfb0c093');
      parms['qop'].should.equal('auth,auth-int');
      parms['rspauth'].should.equal('<PASSWORD>');
      parms['nc'].should.equal('00000001');
      parms['cnonce'].should.equal('abc"d,ef');  // double double quote properly parsed as single double quote
      done();
    } );
  } );
} );
{'fraction_non_alphanumeric': 0.15280113856902575, 'fraction_numerical': 0.08202872299133135, 'mean_word_length': 2.4882671480144403, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 19, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 10, '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': '1856160', 'n_tokens_mistral': 3000, 'n_tokens_neox': 2572, 'n_words': 364}